home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-08 | 146.3 KB | 4,680 lines | [TEXT/MPS ] |
- /*------------------------------------------------------------------------------
-
- File: PanelEditor.cpp
-
- Written by: Steve Smith
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
-
- Description: PanelEditor demonstrates the most basic functions and
- responsibilities of an OpenDoc™ leaf part.
-
-
- Demonstrates: The following recipes were used in implementing the
- PanelEditor:
- 1. Open
- 2. Adding A Display Frame
- 3. Adding A Facet
- 4. Part Drawing
- 5. Refcounting Geometry
- 6. ViewTypes & Presentations
- 7. Display Frame 'ternalization
- 8. Part Init & Externalization
- 9. Part Init & partWrapper
- 10. Part Storage Model
- 11. Persistent Reference
- 12. RefCounting
- 13. Storage Unit
- 14. Activation
- 15. Basic Event Handling
- 16. Menus
- 17. Windows & Dialogs
- 18. Exception Handling
- 19. Memory Manager
- 20. Using Resources
- 21. Lazy Frame Internalization
- 22. Multiple Kind Support
-
-
- Notes: • For methods where it is necessary to call the parent class
- implementation, the calls are made from the SOM class. See
- som_PanelEditor.cpp and the Class Reference to know whether
- you need to call the parent class from any method.
-
- • Panel Editor will, at some point, demonstrate a single source
- base for an "editor" and a "viewer". Throughout the code, you
- will see "#ifndef PE_ViewerBuild". Any code wrapped by the
- ifdef is code that should not execute in the viewer version of
- the part/component/application. Though the implementation is
- incomplete, it should give you some preliminary ideas on how
- to structure your code so that you can provide both an editor
- and a viewer to your customers.
-
- ------------------------------------------------------------------------------*/
-
- // -- Compiler/Preprocessor Switches --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (ie. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with the "ev" parameter set.
- #include <Except.h>
- #endif
-
- // -- PanelEditor Includes --
-
- #ifndef _PANELEDITORGLOBALS_
- #include "PanelEditorGlobals.h"
- #endif
-
- #ifndef _PANELEDITOR_
- #include "PanelEditor.h"
- #endif
-
- #ifndef _LISTITEM_
- #include "ListItem.h"
- #endif
-
- #ifndef _SELECTION_
- #include "Selection.h"
- #endif
-
- #ifndef _PANEL_
- #include "Panel.h"
- #endif
-
- #ifndef _SCROLLINGLIST_
- #include "ScrollingList.h"
- #endif
-
- #ifndef _UNDOPE_
- #include "UndoPE.h"
- #endif
-
- #ifndef _SCROLLBAR_
- #include "Scrollbar.h"
- #endif
-
- #ifndef _FRAMEINFO_
- #include "FrameInfo.h"
- #endif
-
- #ifndef _PANELEDITORDEF_
- #include "PanelEditorDef.h"
- #endif
-
- #ifndef _PANELEDITORUTILS_
- #include "PanelEditorUtils.h"
- #endif
-
- #ifndef _SAMPLECOLLECTIONS_
- #include "SampleCollections.h"
- #endif
-
- #ifndef _PRINTER_
- #include "Printer.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Foci_defined
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODFocusSet_xh
- #include <FocusSet.xh>
- #endif
-
- #ifndef SOM_ODMenuBar_xh
- #include <MenuBar.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODCanvas_xh
- #include <Canvas.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDragAndDrop_xh
- #include <DragDrp.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_ODUndo_xh
- #include <Undo.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _ITEXT_
- #include <IText.h>
- #endif
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- #ifndef _ODMEMORY_
- #include <ODMemory.h>
- #endif
-
- #ifndef _ODNEW_
- #include <ODNew.h>
- #endif
-
- #ifndef _ISOSTR_
- #include <ISOStr.h>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _PLFMDEF_
- #include <PlfmDef.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _TEMPITER_
- #include <TempIter.h>
- #endif
-
- #ifndef _WINUTILS_
- #include <WinUtils.h>
- #endif
-
- // -- Macintosh Includes --
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __DRAG__
- #include <Drag.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif
-
- #ifndef __GXMATH__
- #include <GXMath.h>
- #endif
-
- #pragma segment PanelEditor
-
-
- //==============================================================================
- // PanelEditor
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: Constructor
- // Origin: Panel Editor
- //
- // Description: This is the C++ class constructor.
- //
- // Warnings: You are not allowed to throw an exception from this method.
- //------------------------------------------------------------------------------
-
- PanelEditor::PanelEditor()
- {
- SOM_Trace("PanelEditor","Constructor");
-
- fSelf = kODNULL;
- fDisplayFrames = kODNULL;
- fEmbeddedParts = kODNULL;
- fSelection = kODNULL;
- fPanel = kODNULL;
- fList = kODNULL;
- fPrinter = kODNULL;
-
- fDirty = kODFalse;
- fNegotiating = kODFalse;
- fReadOnlyStorage = kODFalse;
- }
-
- //------------------------------------------------------------------------------
- // Method: Destructor
- // Origin: Panel Editor
- //
- // Description: This is the C++ class destructor.
- //
- // Warnings: You are not allowed to throw an exception from this method.
- //------------------------------------------------------------------------------
-
- PanelEditor::~PanelEditor()
- {
- SOM_Trace("PanelEditor","Destructor");
- }
-
- //==============================================================================
- #pragma mark • Getters/Setters •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: GetSelf
- // Origin: Panel Editor
- //
- // Description: Return the partwrapper object for this part.
- //
- // This is used by the part to ?????
- //------------------------------------------------------------------------------
-
- ODPart* PanelEditor::GetSelf()
- {
- return fSelf;
- }
-
- //------------------------------------------------------------------------------
- // Method: GetEmbeddedItems
- // Origin: Panel Editor
- //
- // Description: Return the partwrapper object for this part.
- //
- // This is used by the part to ?????
- //------------------------------------------------------------------------------
-
- COrderedList* PanelEditor::GetEmbeddedItems()
- {
- return fEmbeddedParts;
- }
-
- //==============================================================================
- #pragma mark • Initialization •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: InitPart
- // Origin: ODPart
- //
- // Description: This method is called when a new instance of this part is being
- // created. The part should prepare itself to run.
- //
- // Parent: The part's parent class was called before this method was
- // dispatched to (see som_PanelEditor.cpp).
- //
- // Warning: It is not appropriate to require user interaction while
- // stationery is being created. Do not present the user with error
- // dialogs or splash screens from this method.
- //------------------------------------------------------------------------------
-
- void PanelEditor::InitPart( Environment* ev,
- ODStorageUnit* storageUnit,
- ODPart* partWrapper )
- {
- SOM_Trace("PanelEditor","InitPart");
-
- TRY
- // To allow editor swapping (translation) at runtime, OpenDoc requires
- // that we pass in a "reference" to ourselves when interacting with the
- // API (ie. WindowState::RegisterWindow(), Dispatcher::RegisterIdle, etc).
- // The "partWrapper" passed to us here and in InitPartFromStorage is the
- // "reference" OpenDoc is asking us to use.
- fSelf = partWrapper;
-
- // We are being created, either as part of generating stationery or
- // by some editor instantiating the part, so the destination storage
- // must be writeable.
- fReadOnlyStorage = kODFalse;
-
- // Call the common initialization code to get set up.
- this->Initialize(ev);
-
- // Create the printer object.
- fPrinter = CPrinter::New(ev, storageUnit);
-
- // Since we have just been created, our state/content info has
- // never been written out, so setting our "dirty" flag will
- // give us a chance to do that.
- this->SetDirty(ev);
-
- CATCH_ALL
- // Clean up will occur in the destructor which will be called
- // shortly after we return the error.
- RERAISE;
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: InitPartFromStorage
- // Origin: ODPart
- //
- // Description: This method is called when a document/stationery is being opened
- // or when the part is internalized by its containing part. The
- // part should merely read in the saved state/content and
- // initialize itself. The part must not alter its storage unit;
- // otherwise, the "Save" menu item becomes enabled without the user
- // actually having made a change to the document.
- //
- // Parent: The part's parent class was called before this method was
- // dispatched to (see som_SamplePart.cpp).
- //------------------------------------------------------------------------------
-
- void PanelEditor::InitPartFromStorage( Environment* ev,
- ODStorageUnit* storageUnit,
- ODPart* partWrapper )
- {
- SOM_Trace("PanelEditor","InitPartFromStorage");
-
- TRY
- // To allow editor swapping (translation) at runtime, OpenDoc requires
- // that we pass in a "reference" to ourselves when interacting with the
- // API (ie. WindowState::RegisterWindow(), Dispatcher::RegisterIdle, etc).
- // The "partWrapper" passed to us here and in InitPart is the
- // "reference" OpenDoc is asking us to use.
- fSelf = partWrapper;
-
- // Are we being opened from a read-only draft? If so, we cannot
- // write anything back out to our storage unit.
- fReadOnlyStorage = ( ODGetDraft(ev,storageUnit)->
- GetPermissions(ev) < kODDPSharedWrite );
-
- // Call the common initialization code to get set up.
- this->Initialize(ev);
-
- // Create the printer object.
- fPrinter = CPrinter::New(ev, storageUnit);
-
- // Read in the state the part was in when it was last Externalized.
- // This allows the part to present the same "environment" the user
- // had the part set up in the last time it was edited.
- this->InternalizeStateInfo(ev, storageUnit);
-
- // Read in the contents for your part editor.
- this->InternalizeContent(ev, storageUnit);
-
- CATCH_ALL
- // Clean up will occur in the destructor which will be called
- // shortly after we return the error.
- RERAISE;
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: Initialize
- // Origin: Panel Editor
- //
- // Description: This method is called during the initialization of the part. The
- // method is used to initialize all fields of the part and to
- // convert ISO types to tokens for faster comparisons throughout
- // the code.
- //
- // If an exception is thrown in this method, it wil be propogated
- // back to OpenDoc which will call our ReleaseAll() method and the
- // class destructor. All memory allocated here will be cleaned up
- // in the ReleaseAll() method.
- //------------------------------------------------------------------------------
-
- void PanelEditor::Initialize( Environment* ev )
- {
- SOM_Trace("PanelEditor","Initialize");
-
- // Grab a reference to the Session object. This is merely for
- // convenience.
- ODSession* session = ODGetSession(ev, fSelf);
-
- // Create a list to keep track of the frames we are being
- // displayed in. Also used for maintenance (i.e., Purging memory).
- fDisplayFrames = new CList;
-
- // Create a list to manage the embedded "list item" objects.
- fEmbeddedParts = new COrderedList;
-
- // Create our selection object.
- fSelection = new CSelection(this, session);
- fSelection->InitSelection();
-
- // Create our scrolling list frame proxy object.
- fList = new CScrollingList;
- fList->InitScrollingList(ev, this);
-
- // Create our panel frame proxy object.
- fPanel = new CPanel;
- fPanel->InitPanel();
-
- // First check to see if the library's global variables have
- // been initialized (meaning another part instantiation is already
- // running).
-
- if ( gGlobalsUsageCount == 0 )
- {
- // Create our globals space. We store the globals in a struct so
- // that we can put them in temp mem. Otherwise, CFM loads the globals
- // with the data fragment of a CFM library in the application heap.
- gGlobals = new PanelEditorGlobals;
-
- // It is required that parts instantiate their menu bars from
- // the base OpenDoc menu bar. This maintains consistency in the
- // default menu items and their placement.
- // Since the object is a copy, we can add and subtract menus and
- // items without affecting other running parts.
- gGlobals->fMenuBar = session->GetWindowState(ev)->CopyBaseMenuBar(ev);
-
- // We will be using the following foci (shared resources) in this
- // part. For convenience, we tokenize the values here and store
- // them for equivalence tests in the activation methods.
- gGlobals->fSelectionFocus = session->Tokenize(ev, kODSelectionFocus);
- gGlobals->fMenuFocus = session->Tokenize(ev, kODMenuFocus);
- gGlobals->fKeyboardFocus = session->Tokenize(ev, kODKeyFocus);
- gGlobals->fModalFocus = session->Tokenize(ev, kODModalFocus);
- gGlobals->fClipboardFocus = session->Tokenize(ev, kODClipboardFocus);
-
- // Also for convenience, we tokenize our part's main presentation
- // and the standard view types.
- gGlobals->fUndefinedPresentation = session->Tokenize(ev, kODPresDefault);
- gGlobals->fMainPresentation = session->Tokenize(ev, kMainPresentation);
- gGlobals->fListPresentation = session->Tokenize(ev, kListPresentation);
-
- gGlobals->fFrameView = session->Tokenize(ev, kODViewAsFrame);
- gGlobals->fLargeIconView = session->Tokenize(ev, kODViewAsLargeIcon);
- gGlobals->fSmallIconView = session->Tokenize(ev, kODViewAsSmallIcon);
- gGlobals->fThumbnailView = session->Tokenize(ev, kODViewAsThumbnail);
-
- // Lastly, we will package the menu and selection focus
- // so that we can request the "set" at activation time.
- gGlobals->fUIFocusSet = session->GetArbitrator(ev)->CreateFocusSet(ev);
- gGlobals->fUIFocusSet->Add(ev, gGlobals->fMenuFocus);
- gGlobals->fUIFocusSet->Add(ev, gGlobals->fKeyboardFocus);
- gGlobals->fUIFocusSet->Add(ev, gGlobals->fSelectionFocus);
-
- // Determine what Script/Language the part is localized for.
- // This is important/necessary for creating OpenDoc's text objects.
- GetEditorScriptLanguage(ev, &gGlobals->fEditorsScript, &gGlobals->fEditorsLanguage);
- GetScriptFontSize(ev, gGlobals->fEditorsScript, &gGlobals->fScriptFont, &gGlobals->fScriptFontSize);
-
- // Get the "untitled" item string from our resources.
- Str31 text;
- ODGetIndString(text, kUntitledNameResID, kUntitledName);
- gGlobals->fUntitledName = CreateIText(gGlobals->fEditorsScript, gGlobals->fEditorsLanguage, (StringPtr)&text);
-
- // The first client of the global variables is running.
- gGlobalsUsageCount = 1;
- }
- else
- // If the globals have been initialized, we just bump the "usage" count so
- // that we know how many part instances are using them.
- {
- gGlobalsUsageCount++;
- }
- }
-
- //==============================================================================
- #pragma mark • Storage •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: Release
- // Origin: ODPart
- //
- // Description: This method is called each time an object releases a reference
- // to the part. If the refcount falls to 0, the part should
- // release the fSelf part reference.
- //
- // Parent: The part's parent class was called before this method was
- // dispatched to (see som_SamplePart.cpp).
- //
- // Warning: If the part releases any other object when the refcount falls to
- // zero, it will need to override the Acquire method so
- // that the object can be referenced again if the parts refcount
- // should be incremented before it is deleted.
- //------------------------------------------------------------------------------
-
- void PanelEditor::Release( Environment* ev )
- {
- SOM_Trace("PanelEditor","Release");
-
- if (fSelf->GetRefCount(ev) == 0)
- ODGetDraft(ev, fSelf)->ReleasePart(ev, fSelf);
- }
-
- //------------------------------------------------------------------------------
- // Method: ReleaseAll
- //
- // Description: This method is called just prior to the part being deleted by
- // the Draft. The part must release all references to all
- // refcounted objects it has stored internally; not doing so, will
- // cause an "invalid ref count" exception/error at some later time.
- //------------------------------------------------------------------------------
-
- void PanelEditor::ReleaseAll( Environment* ev )
- {
- SOM_Trace("PanelEditor","ReleaseAll");
-
- TRY
- // Delete the selection object.
- ODDeleteObject(fSelection);
- // Delete the panel object.
- ODDeleteObject(fPanel);
- // Delete the scrolling list object.
- ODDeleteObject(fList);
-
- // Delete the printer object.
- ODDeleteObject(fPrinter);
-
- // If the last part instance using the globals is released,
- // we need to delete the globals.
-
- if ( --gGlobalsUsageCount == 0 )
- {
- // Release the menubar.
- ODReleaseObject(ev, gGlobals->fMenuBar);
-
- // But first, we need to delete the objects we created
- // and stored in the globals struct.
- ODDeleteObject(gGlobals->fUIFocusSet);
- DisposeIText(gGlobals->fUntitledName);
-
- // Release the thumbnail (PICT) resource.
- if ( gGlobals->fThumbnail )
- {
- ReleaseResource(gGlobals->fThumbnail);
- gGlobals->fThumbnail = kODNULL;
- }
-
- // Now, clean up the globals struct.
- ODDeleteObject(gGlobals);
- }
-
- // Release our display frames.
- if ( fDisplayFrames )
- {
- CListIterator fiter(fDisplayFrames);
- for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
- fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
- {
- // Delete the proxy object and its contents. The frame's
- // refcount will be decremented in the proxy destructor.
- fiter.RemoveCurrent();
- delete proxy;
- }
-
- // Delete the display frame collection.
- ODDeleteObject(fDisplayFrames);
- }
-
- // Release all the embedded items.
- if ( fEmbeddedParts )
- {
- COrdListIterator fiter(fEmbeddedParts);
- for ( CListItem* item = (CListItem*)fiter.First();
- fiter.IsNotComplete();
- item = (CListItem*)fiter.Next() )
- {
- fiter.RemoveCurrent();
- item->Release(ev);
- }
-
- ODDeleteObject(fEmbeddedParts);
- }
-
- CATCH_ALL
- // If something goes wrong while we are cleaning up, we must
- // let the Draft now because there may be some refcounted objects
- // which did not get released. Not to mention, possible memory
- // leaks.
- RERAISE;
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: Purge
- // Origin: ODPart
- //
- // Description: This method is called when the OpenDoc requires more memory for
- // allocating objects and just before a part is deleted. The part
- // should free up as much memory as it can.
- //
- // The part determines which views are being "used" in its display
- // frames. The resources for the unused view types are then purged.
- //------------------------------------------------------------------------------
-
- ODSize PanelEditor::Purge( Environment* ev,
- ODSize /*size*/ )
- {
- SOM_Trace("PanelEditor","Purge");
-
- // Purge is called during the creation of stationery. However,
- // we have not created our internal display frames list, so
- // trying to iterate over it would be fatal.
- if ( fDisplayFrames == kODNULL ) return 0;
-
- ODSize bytesFreed = 0;
- ODBoolean usingThumbnail = kODFalse;
-
- // Iterate over the frames we are displayed through and determine which
- // view types are currently in use.
-
- CListIterator fiter(fDisplayFrames);
- for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
- fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
- {
- // If the display frame is real (has been "connected" or was "added")
- // get its view type; otherwise, ignore it.
- if ( proxy->FrameIsLoaded(ev) )
- {
- ODTypeToken frameView = proxy->GetFrame(ev)->GetViewType(ev);
-
- if ( frameView == gGlobals->fThumbnailView )
- usingThumbnail = kODTrue;
-
- // Release the frame reference, but don't get rid of the
- // proxy object because we're not done with the frame. If
- // all parts release their references the frame will be
- // purged from memory.
- proxy->Purge(ev);
- }
- }
-
- // Based on the usage of the supported view types, free up as much
- // memory as possible.
-
- if ( !usingThumbnail && (gGlobals->fThumbnail != kODNULL) )
- {
- bytesFreed += (ODSize) ODGetHandleSize(gGlobals->fThumbnail);
- ReleaseResource(gGlobals->fThumbnail);
- gGlobals->fThumbnail = kODNULL;
- }
-
- return bytesFreed;
- }
-
- //------------------------------------------------------------------------------
- // Method: InternalizeStateInfo
- // Origin: SamplePart
- //
- // Description: This method is used to read in "state" information for the part.
- // This is information related to the workings of the part editor,
- // not the content.
- //
- // The part writes out a list of weak references to its display
- // frames. This allows the part to reuse the same display frames
- // each time the document is opened. Those references are read
- // back in and validated here.
- //
- // Note: The function StorageUnitGetValue simplifies the use of
- // ODByteArrary, which is required the StorageUnit interface. Look
- // in StorUtil.h/cpp for an example of using the ODByteArray struct.
- //------------------------------------------------------------------------------
-
- void PanelEditor::InternalizeStateInfo( Environment* ev,
- ODStorageUnit* storageUnit )
- {
- SOM_Trace("PanelEditor","InternalizeStateInfo");
-
- ODStorageUnitRef weakRef;
- ODULong size;
-
- // Internalize the part's display frame list.
-
- if ( storageUnit->Exists(ev, kODPropDisplayFrames, kODWeakStorageUnitRefs, 0) )
- {
- storageUnit->Focus(ev, kODPropDisplayFrames, kODPosUndefined,
- kODWeakStorageUnitRefs, 0, kODPosUndefined);
-
- size = storageUnit->GetSize(ev);
- storageUnit->SetOffset(ev, 0);
-
- for ( ODULong offset = 0; offset < size; offset += kODStorageUnitRefSize )
- {
- TRY
- StorageUnitGetValue(storageUnit, ev, kODStorageUnitRefSize, (ODPtr)&weakRef);
-
- if ( storageUnit->IsValidStorageUnitRef(ev, weakRef) )
- {
- // We lazily internalize our display frames, meaning we don't "get"
- // the frame until we absolutely need it. This reduces the time
- // to internalize the part and the amount of memory needed.
-
- // Convert the reference into a runtime id.
- ODID frameID = storageUnit->GetIDFromStorageUnitRef(ev, weakRef);
-
- // Create a proxy class to support the lazy internalization.
- CFrameProxy* proxy = new CFrameProxy;
- proxy->InitFrameProxy(frameID, ODGetDraft(ev,storageUnit));
-
- // Add the proxy to the display frame collection.
- fDisplayFrames->Add(proxy);
- }
- CATCH_ALL
- // consume exception
- ENDTRY
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: InternalizeContent
- // Origin: Panel Editor
- //
- // Description: This method is called during initialization of the part from an
- // existing document. The content of the part should be read in.
- //
- // The part has no intrinsic content, so the part does nothing.
- // The method is here for completeness.
- //------------------------------------------------------------------------------
-
- void PanelEditor::InternalizeContent( Environment* ev,
- ODStorageUnit* storageUnit )
- {
- SOM_Trace("PanelEditor","InternalizeContent");
-
- if ( storageUnit->Exists(ev, kODPropContents, kPanelEditorKind, 0) )
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined,
- kPanelEditorKind, 0, kODPosUndefined);
-
- // Get the number of embedded items we wrote out last time.
-
- ODULong count = 0;
-
- StorageUnitGetValue(storageUnit, ev, sizeof(ODULong), (ODPtr)&count);
-
- for (ODULong i=1; i<=count; i++)
- {
- // Create our handler class for embedded frames and
- // ask it to read its state back in.
- CListItem* item = new CListItem;
- item->InitListItem();
- item->Read(ev, storageUnit);
-
- // Add the resurrected item to our list.
- fEmbeddedParts->AddLast((ODPtr)item);
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: CloneInto
- // Origin: ODPart
- //
- // Description: This method is called during cloning, typically during data
- // interchange operations (ie. Cut/Paste). The part should
- // write out its current state and content.
- //
- // Parent: The part's parent class was called before this method was
- // dispatched to (see som_SamplePart.cpp).
- //------------------------------------------------------------------------------
-
- void PanelEditor::CloneInto( Environment* ev,
- ODDraftKey key,
- ODStorageUnit* destinationSU,
- ODFrame* initiatingFrame )
- {
- SOM_Trace("PanelEditor","CloneInto");
-
- // We must first verify that we've never written to this storage unit.
- // If we have, we should do nothing, otherwise we need to write out
- // the current state of the part content.
-
- if ( destinationSU->Exists(ev, kODPropContents, kPanelEditorKind, 0) == kODFalse )
- {
- // Add the properties we need to successfully externalize
- // ourselves into the destination storage unit.
- this->CheckAndAddProperties(ev, destinationSU);
-
- // Write out the part's state information.
- this->ExternalizeStateInfo(ev, destinationSU, key, initiatingFrame);
-
- // Write out the part's content.
- this->ExternalizeContent(ev, destinationSU, key, initiatingFrame);
- }
-
- // Printing: Externalize the page setup info. It might be dirty even
- // if fDirty is false, so don't put this in the if block above.
- if ( !fReadOnlyStorage && fPrinter )
- {
- TRY
- fPrinter->Externalize(ev);
- CATCH_ALL
- WARN("Err %d externalizing page setup",ErrorCode());
- ENDTRY
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: Externalize
- // Origin: ODPart
- //
- // Description: This method is called when the user saves the document. The part
- // should write out its state and content if changes have occurred
- // and if our storage is writeable.
- //
- // Parent: The part's parent class was called before this method was
- // dispatched to (see som_SamplePart.cpp).
- //------------------------------------------------------------------------------
-
- void PanelEditor::Externalize( Environment* ev )
- {
- SOM_Trace("PanelEditor","Externalize");
-
- TRY
- if ( fDirty && !fReadOnlyStorage)
- {
- // Get our storage unit.
- ODStorageUnit* storageUnit = fSelf->GetStorageUnit(ev);
-
- // Verify that the storage unit has the appropriate properties
- // and values to allow us to run. If not, add them.
- this->CheckAndAddProperties(ev, storageUnit);
-
- // Verify that there are no "bogus" values in the Content
- // property.
- this->CleanseContentProperty(ev, storageUnit);
-
- // Write out the part's state information.
- this->ExternalizeStateInfo(ev, storageUnit, kODNULLKey, kODNULL);
-
- // Write out the part's content.
- this->ExternalizeContent(ev, storageUnit, kODNULLKey, kODNULL);
-
- // Flag our part as no longer being dirty.
- fDirty = kODFalse;
- }
-
- // Printing: Externalize the page setup info. It might be dirty even
- // if fDirty is false, so don't put this in the if block above.
- if ( !fReadOnlyStorage && fPrinter )
- {
- TRY
- fPrinter->Externalize(ev);
- CATCH_ALL
- WARN("Err %d externalizing page setup",ErrorCode());
- ENDTRY
- }
-
- CATCH_ALL
- // Alert the user of the problem.
- this->DoDialogBox(ev, kODNULL, kErrorBoxID, kErrExternalizeFailed);
- // Change the exception value, so the DocShell doesn't display an
- // error dialog.
- SetErrorCode(kODErrAlreadyNotified);
- // Alert the caller.
- RERAISE;
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: ExternalizeKinds
- // Origin: ODPart
- //
- // Description: This method is called when the user wants to save the document
- // with multiple representations of the data. This is especially
- // useful for increasing the portability of documents
- // cross-platform.
- //
- // A part should verify each kind is valid, that it exists in
- // the content property in the correct order, and write the data.
- //
- // Note: For parts which support only on kind, the code can simplified.
- // In this case, it is not necessary to iterate over the kindset
- // because you must, at least, write your preferred kind. The code
- // is shown this way to better illustrate the recipe; it is not
- // wrong, it just does more than it needs to.
- //------------------------------------------------------------------------------
-
- void PanelEditor::ExternalizeKinds(Environment* ev, ODTypeList* kindset)
- {
- SOM_Trace("PanelEditor","ExternalizeKinds");
-
- if ( !fReadOnlyStorage )
- {
- ODBoolean preferredKindWritten = kODFalse;
-
- // Get our storage unit.
- ODStorageUnit* storageUnit = fSelf->GetStorageUnit(ev);
-
- // Verify that the storage unit has the appropriate properties
- // and values to allow us to run. If not, add them.
- this->CheckAndAddProperties(ev, storageUnit);
-
- // Verify that there are no "bogus" values in the Content
- // property.
- this->CleanseContentProperty(ev, storageUnit);
-
- // Iterate over the kindset and write out the content types
- // that we support.
- TempODTypeListIterator tliter(ev, kindset);
- for ( ODType kind = tliter.First(); tliter.IsNotComplete();
- kind = tliter.Next() )
- {
- // Check to see if this is a kind we support. If so, write it.
- if ( ODISOStrCompare(kind, kPanelEditorKind) == 0 )
- {
- // Write out the part's content.
- this->ExternalizeContent(ev, storageUnit, kODNULLKey, kODNULL);
- // This is our preferrend kind so we don't need to write it again.
- // Part editors with more than one kind need to test each kind
- // against the preferred kind to make sure it's been written.
- preferredKindWritten = kODTrue;
- }
- }
-
- // Write out the part's state information.
- this->ExternalizeStateInfo(ev, storageUnit, kODNULLKey, kODNULL);
-
- // Printing: Externalize the page setup info. It might be dirty even
- // if fDirty is false, so don't put this in the if block above.
- if ( !fReadOnlyStorage && fPrinter )
- {
- TRY
- fPrinter->Externalize(ev);
- CATCH_ALL
- WARN("Err %d externalizing page setup",ErrorCode());
- ENDTRY
- }
-
- // Even if the kind set contains no types we support, we must at least
- // write out our current "preferred" kind.
- if ( preferredKindWritten == kODFalse )
- {
- // Write out the part's preferred content kind, which, for PanelEditor,
- // is the only kind.
- this->ExternalizeContent(ev, storageUnit, kODNULLKey, kODNULL);
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: ChangeKind
- // Origin: ODPart
- //
- // Description: This method is called when the changes the part's primary kind
- // and/or when the part editor is switched via the Info dialog.
- //
- // The editor should record the new "preferred" kind and change the
- // UI, if necessary, to allow editing that kind. Don't write the
- // properties/values/data until the Externalize is called.
- //------------------------------------------------------------------------------
-
- void PanelEditor::ChangeKind(Environment* ev, ODType kind)
- {
- if ( ODISOStrCompare(kind, kPanelEditorKind) != 0 )
- THROW(kODErrInvalidValueType);
-
- // Panel Editor only has one kind, so we do nothing.
- }
-
- //------------------------------------------------------------------------------
- // Method: ExternalizeStateInfo
- // Origin: Panel Editor
- //
- // Description: This method is called during externalization of the part. The
- // current "state" of the part should be written out. This "state"
- // information may be lost during Data Interchange operations, so
- // the part needs to recover gracefully if information is missing
- // or incomplete.
- //
- // Note: The function StorageUnitSetValue is a macro which simplifies
- // the use of ODByteArrary, which is required by the StorageUnit
- // interface. Look in StorUtil.h/cpp for an example of using the
- // ODByteArray struct.
- //------------------------------------------------------------------------------
-
- void PanelEditor::ExternalizeStateInfo( Environment* ev,
- ODStorageUnit* storageUnit,
- ODDraftKey key,
- ODFrame* scopeFrame )
- {
- SOM_Trace("PanelEditor","ExternalizeStateInfo");
-
- ODStorageUnitRef weakRef;
- ODStorageUnitID frameID;
- ODID scopeFrameID = ( scopeFrame ? scopeFrame->GetID(ev) : kODNULLID );
- ODDraft* fromDraft = ODGetDraft(ev,fSelf);
-
- // Externalize the part's display frame list.
-
- storageUnit->Focus(ev, kODPropDisplayFrames, kODPosUndefined,
- kODWeakStorageUnitRefs, 0, kODPosUndefined);
-
- // Persistent object references are stored in a side table, rather than
- // in the property/value stream. Thus, deleting the contents of a value
- // will not "delete" the references previously written to that value. To
- // completely "delete" all references written to the value, we must
- // remove the value and add it back.
- storageUnit->Remove(ev);
- storageUnit->AddValue(ev, kODWeakStorageUnitRefs);
-
- CListIterator fiter(fDisplayFrames);
- for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
- fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
- {
- // Get the ID of the frame we are going to weakly reference.
- frameID = proxy->GetID();
-
- // If a draft key exists, then we are being cloned to another draft.
- // We must "weak" clone our display frame and reference the cloned
- // frame. The part re-uses the frameID variable so there aren't two
- // different GetWeakStorageUnitRef calls.
- if ( key )
- frameID = fromDraft->WeakClone(ev, key, frameID, kODNULLID, scopeFrameID);
-
- // Write out weak references to each of the part's display frames.
- storageUnit->GetWeakStorageUnitRef(ev, frameID, weakRef);
- TRY
- StorageUnitSetValue(storageUnit, ev, kODStorageUnitRefSize, (ODPtr)&weakRef);
- CATCH_ALL
- // consume the exception
- ENDTRY
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: ExternalizeContent
- // Origin: Panel Editor
- //
- // Description: This method is called during exteralization of the part. The
- // content of the part should be written out.
- //
- // The part's content consists of references to the other parts
- // embedded in it. The list of embedded items is written here.
- //------------------------------------------------------------------------------
-
- void PanelEditor::ExternalizeContent( Environment* ev,
- ODStorageUnit* storageUnit,
- ODDraftKey key,
- ODFrame* scopeFrame )
- {
- SOM_Trace("PanelEditor","ExternalizeContent");
-
- if ( storageUnit->Exists(ev, kODPropContents, kPanelEditorKind, 0) )
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined,
- kPanelEditorKind, 0, kODPosUndefined);
-
- // If we have written the embedded frame refs out before and
- // things have changed, we need to clear out the old refs
- // before writing the new ones.
- if ( storageUnit->GetSize(ev) > sizeof(ODULong) )
- {
- storageUnit->Remove(ev);
- storageUnit->AddValue(ev, kPanelEditorKind);
- }
-
- // Write the embedded frame count out.
- ODULong count = fEmbeddedParts->Count();
-
- StorageUnitSetValue(storageUnit, ev, sizeof(ODULong), (ODPtr)&count);
-
- // If the key is valid, we must pass the "source" draft to the
- // items so that they can clone themselves.
- ODDraft* draft = (key != kODNULLKey) ? ODGetDraft(ev,fSelf) : kODNULL;
-
- // Then write a strong reference to each of the embedded frames.
- COrdListIterator fiter(fEmbeddedParts);
- for ( CListItem* item = (CListItem*)fiter.First();
- fiter.IsNotComplete();
- item = (CListItem*)fiter.Next() )
- {
- item->Write(ev, storageUnit, draft, key);
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: CleanseContentProperty
- // Origin: Panel Editor
- //
- // Description: This method is called during exteralization of the part so that
- // the part can remove any value in the content property
- // that it cannot "accurately" write to.
- //
- // Note: "Additional" values will be added to a part's content property
- // during Drag & Drop operations.
- //------------------------------------------------------------------------------
-
- void PanelEditor::CleanseContentProperty( Environment* ev,
- ODStorageUnit* storageUnit )
- {
- SOM_Trace("PanelEditor","CleanseContentProperty");
-
- ODULong numValues;
- ODULong index;
-
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined,
- kODNULL, 0, kODPosAll);
-
- numValues = storageUnit->CountValues(ev);
-
- for (index = numValues; index >= 1; index--)
- {
- // Index from 1 to n through the values.
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined,
- kODNULL, index, kODPosUndefined);
-
- // Get the ISO type name for the value. The temp object
- // will automatically delete the returned value when this
- // scope is exited.
- TempODValueType value = storageUnit->GetType(ev);
-
- // If the value type is not one we support, remove it.
- if ( ODISOStrCompare(value, kPanelEditorKind) != 0 )
- storageUnit->Remove(ev);
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: CheckAndAddProperties
- // Origin: Panel Editor
- //
- // Description: This method is called during externalization of the part to
- // verify that all the properties needed to persistently represent
- // the current running state of the part.
- //
- // The part adds the default content property, a preferred editor
- // property (to aid in part binding), and a display frames
- // property.
- //
- // Note: The function StorageUnitSetValue is a macro which simplifies
- // the use of ODByteArrary, which is required the StorageUnit
- // interface. Look in StorUtil.h/cpp for an example of using the
- // ODByteArray struct.
- //------------------------------------------------------------------------------
-
- void PanelEditor::CheckAndAddProperties( Environment* ev,
- ODStorageUnit* storageUnit )
- {
- SOM_Trace("PanelEditor","CheckAndAddProperties");
-
- // Create our content property and preferred content property kind.
-
- if ( !storageUnit->Exists(ev, kODPropContents, kODNULL, 0) )
- storageUnit->AddProperty(ev, kODPropContents);
- if ( !storageUnit->Exists(ev, kODPropContents, kPanelEditorKind, 0) )
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, kODNULL, 0, kODPosAll);
- storageUnit->AddValue(ev, kPanelEditorKind);
- }
-
- // Since we are setting up the preferred kind property, we just write
- // out our default "kind" for the editor. We can write out the user
- // chosen kind in the ExternalizeStateInfo method.
-
- if ( !storageUnit->Exists(ev, kODPropPreferredKind, kODISOStr, 0) )
- {
- TRY
- ODSetISOStrProp(ev, storageUnit, kODPropPreferredKind, kODISOStr, kPanelEditorKind);
- CATCH_ALL
- // Remove the property and value if something went wrong.
- ODSURemoveProperty(ev, storageUnit, kODPropPreferredKind);
- ENDTRY
- }
-
- // Add our display frame list.
-
- if ( !storageUnit->Exists(ev, kODPropDisplayFrames, kODNULL, 0) )
- storageUnit->AddProperty(ev, kODPropDisplayFrames);
- if ( !storageUnit->Exists(ev, kODPropDisplayFrames, kODWeakStorageUnitRefs, 0) )
- {
- storageUnit->Focus(ev, kODPropDisplayFrames, kODPosUndefined, kODNULL, 0, kODPosAll);
- storageUnit->AddValue(ev, kODWeakStorageUnitRefs);
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: SetDirty
- // Origin: Panel Editor
- //
- // Description: This method is called by the part when the content or state of
- // the part has been modified by the user and the "Save" menu item
- // should be enabled.
- //------------------------------------------------------------------------------
-
- void PanelEditor::SetDirty( Environment* ev )
- {
- SOM_Trace("PanelEditor","SetDirty");
-
- // There is no need to repeatedly tell the draft we have changed;
- // once is sufficient.
- if ( !fDirty && !fReadOnlyStorage )
- {
- fDirty = kODTrue;
- ODGetDraft(ev,fSelf)->SetChangedFromPrev(ev);
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: ReadPartInfo
- // Origin: ODPart
- //
- // Description: When a frame is being internalized by the Draft, it will ask the
- // owner (part) to read in its info annotation on the frame.
- //
- // The part uses a C++ helper class to encapsulate the information
- // we store with each frame, so we let it internalize itself from
- // the storage unit view.
- //------------------------------------------------------------------------------
-
- ODInfoType PanelEditor::ReadPartInfo( Environment* ev,
- ODFrame* frame,
- ODStorageUnitView* storageUnitView )
- {
- SOM_Trace("PanelEditor","ReadPartInfo");
-
- CFrameInfo* frameInfo = kODNULL;
-
- TRY
- frameInfo = new CFrameInfo(ODGetSession(ev,fSelf));
- frameInfo->InitFromStorage(ev, storageUnitView);
- CATCH_ALL
- // Clean up the allocated memory.
- ODDeleteObject(frameInfo);
- // Alert the caller.
- RERAISE;
- ENDTRY
-
- return (ODInfoType)frameInfo;
- }
-
- //------------------------------------------------------------------------------
- // Method: WritePartInfo
- // Origin: ODPart
- //
- // Description: When a frame is being externalized by the Draft, it will ask the
- // owner (part) to write out its info annotation on the frame.
- //
- // The part uses a C++ helper class to encapsulate the information
- // we store with each frame, so we let it externalize itself to
- // the storage unit view.
- //------------------------------------------------------------------------------
-
- void PanelEditor::WritePartInfo( Environment* ev,
- ODInfoType partInfo,
- ODStorageUnitView* storageUnitView )
- {
- SOM_Trace("PanelEditor","WritePartInfo");
-
- // Tell our frame info class to write itself out to the prefocused
- // storage unit.
- ((CFrameInfo*) partInfo)->Externalize(ev, storageUnitView);
- }
-
- //------------------------------------------------------------------------------
- // Method: ClonePartInfo
- // Origin: ODPart
- //
- // Description: When a frame is being cloned by the Draft, it will ask the owner
- // (part) to clone its info annotation on the frame.
- //
- // The part uses a C++ helper class to encapsulate the information
- // we store with each frame, so we let it clone itself to the
- // storage unit view.
- //------------------------------------------------------------------------------
-
- void PanelEditor::ClonePartInfo( Environment* ev,
- ODDraftKey key,
- ODInfoType partInfo,
- ODStorageUnitView* storageUnitView,
- ODFrame* scopeFrame )
- {
- SOM_Trace("PanelEditor","ClonePartInfo");
-
- // Tell our frame info class to write itself out into the pre-
- // focused storage unit.
- ((CFrameInfo*) partInfo)->CloneInto(ev, key, storageUnitView, scopeFrame);
- }
-
- //==============================================================================
- #pragma mark • Layout •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: DisplayFrameAdded
- // Origin: ODPart
- //
- // Description: This method is called in response to a frame being created for
- // the part.
- //
- // The part records the existence of a new display frame in its
- // internal display frame list, as well as, verify that the frame
- // is "set up" correctly (i.e., valid viewType). The part also
- // creates and stores its "frame info" class in the new frame.
- //------------------------------------------------------------------------------
-
- void PanelEditor::DisplayFrameAdded( Environment* ev, ODFrame* frame )
- {
- SOM_Trace("PanelEditor","DisplayFrameAdded");
-
- // If we are being embedded into another part, the presentation field
- // will be NULL or undefined; we need to set it something meaningful.
- // The view field may also be null, if so, we prefer to be displayed
- // in a frame view.
-
- if ( frame->GetPresentation(ev) == kODNullTypeToken ||
- frame->GetPresentation(ev) == gGlobals->fUndefinedPresentation )
- frame->SetPresentation(ev, gGlobals->fMainPresentation);
-
- if ( frame->GetViewType(ev) == kODNullTypeToken )
- frame->SetViewType(ev, gGlobals->fFrameView);
-
- // Hang our "state" info off of the new display frame. We use
- // the CFrameInfo object for activation, updating, and window
- // maintenance.
- CFrameInfo* frameInfo = new CFrameInfo(ODGetSession(ev,fSelf));
- frame->SetPartInfo(ev, (ODInfoType)frameInfo);
-
- // If the frame being added is a root frame, we know that a window
- // is associated with this frame. Notify ourselves that we need to
- // clean it up when the frame goes away.
- if ( frame->IsRoot(ev) )
- frameInfo->SetShouldDisposeWindow(kODTrue);
-
- // The proxy class will refcount the frame passed to it, so we
- // don't need to worry about refcounting the display frame.
- CFrameProxy* proxy = new CFrameProxy;
- proxy->InitFrameProxy(ev,frame);
-
- // Add the proxy to the display frame collection.
- fDisplayFrames->Add(proxy);
-
- // Since we maintain a persistent list of weak references to our
- // display frames, having one added to the part dirties it.
- this->SetDirty(ev);
-
- // If the frame's presentation is "main", we need to create a list
- // and panel frame inside of it.
- if ( frame->GetPresentation(ev) == gGlobals->fMainPresentation )
- {
- // Ask the list proxy to create a frame inside the root frame.
- fList->SetPartDisplayed(ev, fSelf);
- fList->AddFrame(ev, frame);
-
- // Ask the panel proxy to create a frame inside the root frame.
- fPanel->AddFrame(ev, frame);
-
- // Negotiate for more frame space?
- if ( !frame->IsRoot(ev) )
- {
- ODRect bounds;
- TempODShape frameShape = frame->AcquireFrameShape(ev,kODNULL);
- frameShape->GetBoundingBox(ev, &bounds);
-
- // If the frame we've been given is too small, remember to request a larger
- // frame shape in FacetAdded().
- if ( FixedToInt(bounds.Height()) < this->GetMinHeight() ||
- FixedToInt(bounds.Width()) < this->GetMinWidth() )
- {
- frameInfo->SetShouldNegotiate(kODTrue);
- }
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: DisplayFrameConnected
- // Origin: ODPart
- //
- // Description: This method is called when one of our display frames, previously
- // written out, is internalized. This method is called instead of
- // DisplayFrameAdded because a "new" frame is not being created;
- // an existing one is being reconstituted.
- //
- // The part first checks to see if we can match its frame to an
- // ID in the Display frame list; if so, we put the frame into the
- // proxy. For frames we do not recognize, just add them.
- //
- // Warning: This method may be calle,d during editor swapping, with a frame
- // not recognized by the part. This is ok. Just treat the case as
- // if a "new" frame were being added to the part.
- //------------------------------------------------------------------------------
-
- void PanelEditor::DisplayFrameConnected( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","DisplayFrameConnected");
-
- // Iterate over our display collection to match the frame with
- // an existing proxy with the correct frame ID. If we find it,
- // replace the ID with the actual frame. If we don't find it,
- // signal an error.
- ODBoolean found = kODFalse;
- CListIterator fiter(fDisplayFrames);
- for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
- fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
- {
- if ( proxy->GetID() == frame->GetID(ev) )
- {
- // The proxy class will refcount the frame passed to it, so we
- // don't need to worry about refcounting the display frame.
- proxy->SetFrame(ev,frame);
- found = kODTrue;
- }
- }
-
- // Parts typically operate under the assumption that they have previous
- // knowledge of a frame before it is connected to it. This knowledge
- // should come from having read in the frame reference when the part
- // was internalized. If the frame is an "unknown", the part was probably
- // bound to another editors storage unit because the editor is missing or
- // the user changed the editor in the Info dialog.
- if ( found )
- {
- // Now that we know we are operating on a valid frame, prepare it
- // based on the presentation it displays.
- if ( frame->GetPresentation(ev) == gGlobals->fMainPresentation )
- {
- // If the frame being added is a root frame, we know that a window
- // is associated with this frame. Notify ourselves that we need to
- // clean it up when the frame goes away.
- if ( frame->IsRoot(ev) )
- {
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- frameInfo->SetShouldDisposeWindow(kODTrue);
- }
-
- // Register the root frame with the panel frame proxy object.
- fList->SetPartDisplayed(ev, fSelf);
- fList->AddFrame(ev, frame);
-
- // Register the root frame with the panel frame proxy object.
- fPanel->AddFrame(ev, frame);
- }
- }
- else
- {
- // If an unrecognizable frame is connected to us, treat it like a "new"
- // frame and call our method to add it.
- this->DisplayFrameAdded(ev, frame);
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: DisplayFrameRemoved
- //
- // Description: This method is called in response to a frame being removed from
- // the part.
- //
- // The part removes the frame from its internal display frame list
- // and reliquishes any foci that it still owned. Lastly, if the
- // frame has a source frame (it was the root frame of a part
- // window), we will record the part window bounds so that any
- // subsequent part windows opened on the source frame will appear
- // in the same location.
- //------------------------------------------------------------------------------
-
- void PanelEditor::DisplayFrameRemoved( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","DisplayFrameRemoved");
-
- TRY
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- // Make sure the frame going away does not own any foci. Forgetting
- // to do this, will cause a "refcounting" error when the frame
- // is deleted by the draft.
- this->RelinquishAllFoci(ev, frame);
-
- // If removing a child window, show zoom rects back to source.
- // NOTE: This has to be done before CleanupDisplayFrame because
- // CleanupDisplayFrame will remove the relationship.
- if ( frame->IsRoot(ev) && frameInfo->HasSourceFrame() )
- {
- TempODWindow window = frame->AcquireWindow(ev);
- this->ZoomPartWindow(ev, frameInfo->GetSourceFrame(ev),
- window, kWindowClosing);
- }
-
- // Clean up the embedded frames; both ours and other parts.
- this->CleanupEmbeddedFrames(ev, frame, kFrameRemoved);
- // Clean up the display frame.
- this->CleanupDisplayFrame(ev, frame, kFrameRemoved);
- // Clean up any associated window.
- this->CleanupWindow(ev, frame);
- // Dispose of the frame's runtime state info.
- frame->SetPartInfo(ev, (ODInfoType) kODNULL);
- ODDeleteObject(frameInfo);
-
- // Remove the display frame from our collection.
- CListIterator fiter(fDisplayFrames);
- for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
- fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
- {
- if ( ODObjectsAreEqual(ev, proxy->GetFrame(ev), frame) )
- {
- // Delete the proxy object and its contents. The frame's
- // refcount will be decremented in the proxy destructor.
- fiter.RemoveCurrent();
- delete proxy;
- }
- }
-
- // Since we maintain a persistent list of weak references to our
- // display frames, having one removed from the part dirties it.
- this->SetDirty(ev);
-
- CATCH_ALL
- // Alert the user of the problem.
- this->DoDialogBox(ev, frame, kErrorBoxID, kErrRemoveFrame);
- // Change the exception value, so the DocShell doesn't display an
- // error dialog.
- SetErrorCode(kODErrAlreadyNotified);
- // Alert the caller.
- RERAISE;
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DisplayFrameClosed
- //
- // Description: This method is called in response to a frame being closed as a
- // result of the document having been closed by the user.
- //
- // The part behaves much the same way that it would if a frame were
- // removed (see above), except that we don't need to cache runtime
- // information.
- //------------------------------------------------------------------------------
-
- void PanelEditor::DisplayFrameClosed( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","DisplayFrameClosed");
-
- TRY
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- // Make sure the frame going away does not own any foci. Forgetting
- // to do this, will cause a "refcounting" error when the frame
- // is deleted by the draft.
- this->RelinquishAllFoci(ev, frame);
-
- // Clean up the embedded frames; both ours and other parts.
- this->CleanupEmbeddedFrames(ev, frame, kFrameClosed);
- // Clean up the display frame.
- this->CleanupDisplayFrame(ev, frame, kFrameClosed);
- // Clean up any associated window.
- this->CleanupWindow(ev, frame);
- // Dispose of the frame's runtime state info.
- frame->SetPartInfo(ev, (ODInfoType) kODNULL);
- ODDeleteObject(frameInfo);
-
- // Remove the display frame from our collection.
- CListIterator fiter(fDisplayFrames);
- for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
- fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
- {
- if ( proxy->GetID() == frame->GetID(ev) )
- {
- // Release the frame reference, but don't get rid of the
- // proxy object because "closed" frames may be reconnected
- // before the document is closed.
- proxy->Purge(ev);
- }
- }
-
- CATCH_ALL
- // Alert the user of the problem.
- this->DoDialogBox(ev, frame, kErrorBoxID, kErrRemoveFrame);
- // Change the exception value, so the DocShell doesn't display an
- // error dialog.
- SetErrorCode(kODErrAlreadyNotified);
- // Alert the caller.
- RERAISE;
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: CleanupEmbeddedFrames
- // Origin: PanelEditor
- //
- // Description: This method is called when a frame has been closed or removed.
- // The method cleans up the references and state information stored
- // in the CFrameInfo class.
- //------------------------------------------------------------------------------
-
- void PanelEditor::CleanupEmbeddedFrames(Environment* ev,
- ODFrame* frame,
- ODBoolean frameRemoved )
- {
- SOM_Trace("PanelEditor","CleanupEmbeddedFrames");
-
- ODError error = noErr;
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- TRY
- // Close the embedded frames, if this frame has any.
- if ( frame->GetPresentation(ev) == gGlobals->fMainPresentation )
- {
- if ( frameRemoved )
- {
- // Ask the panel proxy to remove the frame embedded in this one.
- fList->RemoveFrame(ev, frame);
-
- // Ask the panel proxy to remove the frame embedded in this one.
- fPanel->RemoveFrame(ev, frame);
- }
- else
- {
- // Ask the panel proxy to close the frame embedded in this one.
- fList->CloseFrame(ev, frame);
-
- // Ask the panel proxy to close the frame embedded in this one.
- fPanel->CloseFrame(ev, frame);
- }
- }
- else if ( frame->GetPresentation(ev) == gGlobals->fListPresentation )
- {
- // Remove all the items from the selection.
- if ( fSelection )
- fSelection->Empty(ev, kODFalse);
- }
- CATCH_ALL
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: CleanupDisplayFrame
- // Origin: PanelEditor
- //
- // Description: This method is called when a frame has been closed or removed.
- // The method cleans up the references and state information stored
- // in the CFrameInfo class.
- //------------------------------------------------------------------------------
-
- void PanelEditor::CleanupDisplayFrame( Environment* ev,
- ODFrame* frame,
- ODBoolean frameRemoved )
- {
- SOM_Trace("PanelEditor","CleanupDisplayFrame");
-
- ODError error = noErr;
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- TRY
- // If we are the root of a child window, we need to notify
- // our source frame that we are going away.
- if ( frameInfo->HasSourceFrame() )
- {
- ODFrame* sourceFrame = frameInfo->GetSourceFrame(ev);
- CFrameInfo* sourceFrameInfo = (CFrameInfo*) sourceFrame->GetPartInfo(ev);
-
- if ( frameRemoved )
- {
- // Invalidate the source frame. We do this because the
- // source frame may have a unique display when it has
- // been opened into a part window. This forces the
- // frame to redraw "not opened".
- sourceFrame->Invalidate(ev, kODNULL, kODNULL);
- }
-
- // Tell the source frame that its dependent is going away.
- sourceFrameInfo->ReleaseDependentFrame(ev);
-
- // Release our reference to the source frame.
- frameInfo->ReleaseSourceFrame(ev);
-
- // If the frame is the root, it is a part window going away
- // and we need to notify our source frame that it no longer
- // has a part window.
- if ( frame->IsRoot(ev) )
- sourceFrameInfo->SetPartWindow(ev, kODNULL);
- }
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- TRY
- // If the frame was removed from the document, we need to remove
- // any child window displaying that frame.
- if ( frameRemoved )
- {
- // If we have a child window, we need to close it.
- ODWindow* window = frameInfo->AcquirePartWindow(ev);
-
- if ( window )
- {
- frameInfo->SetPartWindow(ev, kODNULL);
- window->CloseAndRemove(ev);
- }
- }
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- TRY
- // If we have dependent frames, we need to notify them that we
- // are going away.
-
- if ( frameInfo->HasDependentFrame() )
- {
- // Get the frame that is dependent on this one. We can safely
- // do this because we only reference our own display frames.
- ODFrame* dependentFrame = frameInfo->GetDependentFrame(ev);
- CFrameInfo* dependentFrameInfo = (CFrameInfo*) dependentFrame->GetPartInfo(ev);
-
- // Tell the dependent frame that its source is going away.
- dependentFrameInfo->ReleaseSourceFrame(ev);
-
- // Release our reference to the dependent frame.
- frameInfo->ReleaseDependentFrame(ev);
- }
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- // If anything went wrong, signal an error.
- THROW_IF_ERROR(error);
- }
-
- //------------------------------------------------------------------------------
- // Method: AttachSourceFrame
- // Origin: ODPart
- //
- // Description: If the part which we are contained in is opened into a part
- // window, it is required to iterate over its embedded frames and
- // add new display frames in the part window. After each new
- // embedded frame is created, this method will be called.
- //
- // Given all that, and given our lack of interesting
- // content, we just validate the frame and attach it to its source.
- //------------------------------------------------------------------------------
-
- void PanelEditor::AttachSourceFrame(Environment* ev,
- ODFrame* frame,
- ODFrame* sourceFrame )
- {
- SOM_Trace("PanelEditor","AttachSourceFrame");
-
- // Tell the new frame about its source.
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- frameInfo->SetSourceFrame(ev, sourceFrame);
-
- // And tell the source about its new dependent.
- frameInfo = (CFrameInfo*) sourceFrame->GetPartInfo(ev);
- frameInfo->SetDependentFrame(ev, frame);
-
- // In both cases, refcounting of the frame and sourceFrame is
- // handled by the CFrameInfo class.
-
- if ( frame->GetPresentation(ev) == gGlobals->fMainPresentation )
- {
- // Ask the panel object to attach the appropriate frames.
- fList->AttachSourceFrame(ev, frame, sourceFrame);
-
- // Ask the panel object to attach the appropriate frames.
- fPanel->AttachSourceFrame(ev, frame, sourceFrame);
- }
- else if ( frame->GetPresentation(ev) == gGlobals->fListPresentation )
- {
- // Instruct the list to attach embedded items to their sources.
- fList->SourceFrameAttached(ev,frame,sourceFrame);
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: EmbedNewItem
- // Origin: PanelEditor
- //
- // Description: This method is called by the Drop method to clone and embed an
- // interchange storageunit into the list.
- //------------------------------------------------------------------------------
-
- void PanelEditor::EmbedNewItem( Environment* ev,
- ODFacet* facet,
- ODID partID)
- {
- SOM_Trace("PanelEditor","EmbedNewItem");
-
- ODDraft* draft = ODGetDraft(ev, fSelf);
- TempODPart newPart = draft->AcquirePart(ev, partID);
-
- THROW_IF_NULL(newPart);
-
- // Ask the list to create embedded frames for the new part.
- CListItem* newItem = fList->EmbedPart(ev, newPart);
-
- TRY
- if ( newItem )
- {
- // Add the proxy to our embedded parts collection.
- fEmbeddedParts->AddLast((ODPtr)newItem);
-
- // The "dropped" item becomes the current selection
- fSelection->Add(ev, newItem);
- // Change the panel frame display to the newly selected item.
- fPanel->ChangeDisplayItem(ev, newItem);
- }
-
- CATCH_ALL
- fSelection->Empty(ev);
- if ( newItem ) newItem->Release(ev);
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: RemoveListItem
- // Origin: PanelEditor
- //
- // Description: This method is called in
- //------------------------------------------------------------------------------
-
- void PanelEditor::RemoveListItem(Environment* ev, CListItem* item)
- {
- SOM_Trace("PanelEditor","RemoveListItem");
-
- // Remove the item from our embedded parts collection.
- fEmbeddedParts->Remove((ODPtr)item);
- // Release the parts's reference to the item.
- item->Invalidate(ev);
- item->Release(ev);
- }
-
- //------------------------------------------------------------------------------
- // Method: ViewTypeChanged
- // Origin: ODPart
- //
- // Description: This method is called in response to one of our display frame's
- // viewType field being modified. We call this method on ourselves
- // when new display frames are added, but it call also be called
- // when the user changes the view in the "part info" dialog.
- //
- // The part first loads the appropriate view icons if needed and
- // then calculates a new "used" shape based on the bounds of the
- // new view type. If any problems occur while changing the view,
- // the part defaults back to frame view (the part's default view).
- //------------------------------------------------------------------------------
-
- void PanelEditor::ViewTypeChanged( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","ViewTypeChanged");
-
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- ODTypeToken view = frame->GetViewType(ev);
- ODTypeToken previousView = frameInfo->GetPreviousViewType();
-
- // If the view changes from frame to icon, or from icon to frame,
- // we must show/hide the embedded frames/content.
-
- if ( previousView == gGlobals->fFrameView &&
- view != gGlobals->fFrameView )
- {
- fList->RemoveFacets(ev, frame);
- fPanel->RemoveFacets(ev, frame);
- }
- else if ( previousView != gGlobals->fFrameView &&
- view == gGlobals->fFrameView )
- {
- fList->AddFacets(ev, frame);
- fPanel->AddFacets(ev, frame);
- }
-
- // Change this frame's used shape to match the new view setting.
- TempODShape newUsedShape = this->CalcNewUsedShape(ev, frame);
-
- frame->Invalidate(ev, kODNULL, kODNULL);
- frame->ChangeUsedShape(ev, newUsedShape, kODNULL);
- frame->Invalidate(ev, kODNULL, kODNULL);
-
- // Remember the view we've just be set to.
- frameInfo->SetPreviousViewType(view);
- }
-
- //------------------------------------------------------------------------------
- // Method: CalcNewUsedShape
- // Origin: PanelEditor
- //
- // Description: This method is called in response to one of display frame's view
- // being changed. The method calculates the appropriate usedShape
- // for the new view type.
- //------------------------------------------------------------------------------
-
- ODShape* PanelEditor::CalcNewUsedShape( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","CalcNewUsedShape");
-
- ODShape* usedShape = kODNULL;
- ODTypeToken view = frame->GetViewType(ev);
-
- ODVolatile(usedShape);
-
- // If the view is "frame", we intentionally return a nil shape;
- // doing so, will reset the used shape to equal the frame shape.
-
- if ( view == gGlobals->fLargeIconView ||
- view == gGlobals->fSmallIconView ||
- view == gGlobals->fThumbnailView )
- {
- TRY
- Rect bounds;
- RgnHandle usedRgn = ODNewRgn();
-
- if ( view == gGlobals->fLargeIconView || view == gGlobals->fSmallIconView )
- {
- // Focus to our library's resource fork so we can access our icons.
- CUsingLibraryResources res;
-
- // Set the bounds rect for the icon size.
- SetRect(&bounds, 0, 0,
- (view == gGlobals->fLargeIconView) ? kODLargeIconSize : kODSmallIconSize,
- (view == gGlobals->fLargeIconView) ? kODLargeIconSize : kODSmallIconSize);
-
- // Convert the icon mask into a Region.
- OSErr error = IconIDToRgn(usedRgn, &bounds, atAbsoluteCenter, kBaseResourceID);
- }
- else if ( view == gGlobals->fThumbnailView )
- {
- PicHandle thumbnail = this->GenerateThumbnail(ev, frame);
-
- if ( thumbnail )
- bounds = (**thumbnail).picFrame;
- else
- SetRect(&bounds, 0, 0, kODThumbnailSize, kODThumbnailSize);
-
- RectRgn(usedRgn,&bounds);
- }
-
- usedShape = frame->CreateShape(ev);
- usedShape->SetQDRegion(ev, usedRgn);
-
- CATCH_ALL
- ODSafeReleaseObject(usedShape);
- ENDTRY
- }
-
- return usedShape;
- }
-
- //------------------------------------------------------------------------------
- // Method: UpdateFrame
- // Origin: PanelEditor
- //
- // Description: This method is called in response to one of our
- //------------------------------------------------------------------------------
-
- void
- PanelEditor::UpdateFrame( Environment* ev,
- ODFrame* frame,
- ODTypeToken view,
- ODShape* usedShape )
- {
- SOM_Trace("PanelEditor","UpdateFrame");
-
- TRY
- // Update the frame to have the new view and UsedShape.
- frame->Invalidate(ev, kODNULL, kODNULL);
- frame->SetViewType(ev, view);
- frame->ChangeUsedShape(ev, usedShape, kODNULL);
- frame->Invalidate(ev, kODNULL, kODNULL);
- CATCH_ALL
- // Failing isn't great, but we can live with it, so don't set ev.
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: FrameShapeChanged
- // Origin: ODPart
- //
- // Description: This method is called in response to a frame's shape being
- // altered, either by the user or the part we are embedded in.
- //
- // To keep all attached frames in sync, we need to propogate the
- // new frame shape the frames dependent on the changed frame. This
- // is done by observing the display frames stored in the frame info
- // and calling RequestFrameShape for each.
- //------------------------------------------------------------------------------
-
- void PanelEditor::FrameShapeChanged( Environment* ev, ODFrame* frame )
- {
- SOM_Trace("PanelEditor","FrameShapeChanged");
-
- // If the frame is the root frame of a part or document window, it should
- // have no effect on its attached frames or source frame.
-
- if ( frame->GetPresentation(ev) == gGlobals->fMainPresentation )
- {
- // We have strict size requirements, make sure our "new" frameshape
- // meets those requirements; if not, make changes.
-
- if ( !fNegotiating )
- {
- Rect box;
- GetQDFrameBounds(ev, frame, &box);
-
- ODSShort slop = (box.bottom-box.top-2*kListTopEdge) % kListItemHeight;
- if ( slop && slop < kListItemHeight/2 )
- box.bottom -= slop;
- else if ( slop )
- box.bottom += (kListItemHeight-slop);
-
- if ( slop )
- {
- if ( frame->IsRoot(ev) )
- {
- TempODWindow window = frame->AcquireWindow(ev);
- THROW_IF_NULL(window);
- ODPlatformWindow windowPtr = window->GetPlatformWindow(ev);
-
- ODSShort screenBottom = ODQDGlobals.screenBits.bounds.bottom;
- ODSShort windowTop = (**(*(WindowPeek)windowPtr).contRgn).rgnBBox.top;
-
- while ( (windowTop + box.bottom) >= screenBottom )
- box.bottom -= kListItemHeight;
-
- fNegotiating = kODTrue;
- SizeWindow(windowPtr, box.right, box.bottom, kODTrue);
- TRY
- window->AdjustWindowShape(ev);
- CATCH_ALL
- ENDTRY
- fNegotiating = kODFalse;
- }
- else
- {
- ODRect bounds(box);
- TempODShape tShape = frame->CreateShape(ev);
- tShape->SetRectangle(ev, &bounds);
-
- fNegotiating = kODTrue;
- TRY
- TempODShape rtnShape = frame->RequestFrameShape(ev, tShape, kODNULL);
- CATCH_ALL
- ENDTRY
- fNegotiating = kODFalse;
- }
- }
-
- // Resize the List and Panel frames.
- fList->Resize(ev, frame);
- fPanel->Resize(ev, frame);
-
- frame->Invalidate(ev, kODNULL, kODNULL);
- }
- }
-
- // Adjust the "used" shape for the new frame shape.
- TempODShape usedShape = this->CalcNewUsedShape(ev, frame);
- frame->ChangeUsedShape(ev, usedShape, kODNULL);
- }
-
- //------------------------------------------------------------------------------
- // Method: RequestFrameShape
- // Origin: ODPart
- //
- // Description: This method is called when an embedded part wishes to negotiate
- // for a different frame shape. Since our view is static, we don't
- // allow embedded parts to change their frame shape. To prevent
- // part from changing its shape, we always return the "current"
- // frame shape.
- //------------------------------------------------------------------------------
-
- ODShape* PanelEditor::RequestFrameShape(Environment *ev,
- ODFrame* embeddedFrame,
- ODShape* /*frameShape*/)
- {
- SOM_Trace("PanelEditor","RequestFrameShape");
-
- // We don't allow embedded items to resize themselves, so we just get the
- // current frameShape and pass it back to the part.
-
- TempODShape frameShape = embeddedFrame->AcquireFrameShape(ev, kODNULL);
- return frameShape->Copy(ev);
- }
-
- //------------------------------------------------------------------------------
- // Method: Open
- // Origin: ODPart
- //
- // Description: This method is called when OpenDoc, a containing part, or the
- // active editor would like to open a frame into a seperate window.
- // If a source frame is passed into this method, the editor is
- // being asked one of two things. If the frame is the root, we are
- // being asked to open an existing document. If the frame is not
- // the root, we are being asked to open a part window. If a source
- // frame is not specified, the editor is being asked to open a new
- // window.
- //------------------------------------------------------------------------------
-
- ODID PanelEditor::Open( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","Open");
-
- ODID windowID;
- TempODWindow window(kODNULL);
-
- WindowProperties* windowProperties = kODNULL;
- ODVolatile(windowProperties);
-
- TRY
- // Because the frame parameter being passed to us can be one of
- // three things, we must determine what it is; either the root
- // frame of a existing document, the source frame for a part
- // window, or null if we are opening a new document.
-
- if ( frame == kODNULL )
- {
- // Calculate the bounding rectangle for a new window
- Rect windowRect = this->CalcPartWindowSize(ev, kODNULL);
- // Get the default setting for a document window.
- windowProperties = this->GetDefaultWindowProperties(ev, kODNULL, &windowRect);
- // Create a Mac Window and register it with OpenDoc.
- window = this->CreateWindow(ev, kODNULL, kODFrameObject, windowProperties);
- }
- else if ( frame->IsRoot(ev) )
- {
- // Get the previously saved settings for the document window.
- windowProperties = this->GetSavedWindowProperties(ev, frame);
-
- if ( windowProperties == kODNULL )
- {
- // Calculate the bounding rectangle for a new window
- Rect windowRect = this->CalcPartWindowSize(ev, frame);
- // Get the default setting for a document window.
- windowProperties = this->GetDefaultWindowProperties(ev, kODNULL, &windowRect);
- }
-
- // Create a Mac Window and register it with OpenDoc.
- window = this->CreateWindow(ev, frame, kODFrameObject, windowProperties);
-
- // We release the source frame here because we didn't call
- // EndGetWindowProperties and becuase we are done with it.
- ODReleaseObject(ev, windowProperties->sourceFrame);
- }
- else // frame is a source frame
- {
- window = this->AcquireFramesWindow(ev, frame);
-
- if ( window == kODNULL )
- {
- // Calculate the bounding rectangle for a new window
- Rect windowRect = this->CalcPartWindowSize(ev, frame);
- // Get the default setting for a document window.
- windowProperties = this->GetDefaultWindowProperties(ev, frame, &windowRect);
- // Create a Mac Window and register it with OpenDoc.
- window = this->CreateWindow(ev, kODNULL, kODFrameObject, windowProperties);
-
- // Tell the source frame that it is opened in a part window.
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- frameInfo->SetPartWindow(ev, window);
-
- this->ZoomPartWindow(ev, frame, window, kWindowOpening);
- }
- }
-
- // Creates the root facet for the window and notifies the
- // part.
- window->Open(ev);
- // Makes the window visible.
- window->Show(ev);
- // Activates and selects the window.
- window->Select(ev);
-
- // Cleanup allocate memory.
- ODDeleteObject(windowProperties);
-
- // Get window id to return.
- windowID = (window ? window->GetID(ev) : kODNULLID);
-
- CATCH_ALL
- // If we threw early, the source frame's refcount may be too high.
- if ( windowProperties )
- ODReleaseObject(ev, windowProperties->sourceFrame);
- // Cleanup the created items.
- ODDeleteObject(windowProperties);
- windowID = kODNULLID;
- // Alert the caller.
- RERAISE;
- ENDTRY
-
- return windowID;
- }
-
- //------------------------------------------------------------------------------
- // Method: AcquireFramesWindow
- //
- // Description: This method is called by the part when a frame, that has been
- // previously opened, is being opened again.
- //
- // The method retrieves the existing window for the frame and
- // returns it.
- //------------------------------------------------------------------------------
-
- ODWindow* PanelEditor::AcquireFramesWindow( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","AcquireFramesWindow");
-
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- ODWindow* window = frameInfo->AcquirePartWindow(ev);
-
- return window;
- }
-
- //------------------------------------------------------------------------------
- // Method: CreateWindow
- // Origin: PanelEditor
- //
- // Description: This method is called by the part when a window needs to be
- // created for a frame being opened.
- //
- // The part uses the information passed in windowProperties to
- // create the appropriate window. The generated window is
- // registered with OpenDoc as a new window (RegisterWindow) or as a
- // window from an existing document (RegisterWindowForFrame).
- //------------------------------------------------------------------------------
-
- ODWindow* PanelEditor::CreateWindow( Environment* ev,
- ODFrame* frame,
- ODType frameType,
- WindowProperties* windowProperties)
- {
- SOM_Trace("PanelEditor","CreateWindow");
-
- ODPlatformWindow platformWindow = kODNULL; ODVolatile(platformWindow);
- ODWindow* window = kODNULL;
-
- // We force the "visible" flag for new and old windows so that we
- // always get an activate event when the window is displayed. This
- // is done to generate a consistent activation mechanism.
- windowProperties->wasVisible = kODFalse;
-
- // Using the name and the calculated rectangle, create a new window.
- platformWindow = NewCWindow((Ptr)ODNewPtr(sizeof(WindowRecord)),
- &(windowProperties->boundsRect),
- windowProperties->title,
- windowProperties->wasVisible,
- windowProperties->procID,
- (WindowPtr)-1L,
- windowProperties->hasCloseBox,
- windowProperties->refCon);
-
- if ( platformWindow )
- {
- TRY
- ODWindowState* windowState = ODGetSession(ev,fSelf)->GetWindowState(ev);
-
- // Shoud the window be saved in the document? Yes if the root frame is
- // persistent.
- ODBoolean saveWindow = (ODISOStrCompare(frameType,kODFrameObject) == 0);
-
- // Tell the window object that we will be disposing the window record
- // when the root frame is closed/removed.
- ODBoolean shouldDispose = kODFalse;
-
- // Determine whether we are creating a new window (frame is null),
- // or opening a previous saved window (frame is valid).
-
- if ( frame == kODNULL )
- {
- // Tell OpenDoc about it by creating an OpenDoc window object.
- window = windowState->
- RegisterWindow(ev,
- platformWindow, // Macintosh WindowPtr
- frameType, // Frame type (Persistent/Non-persistent)
- windowProperties->isRootWindow, // Is this a document window?
- windowProperties->isResizable, // Is this window resizeable?
- windowProperties->isFloating, // Is this window floating?
- saveWindow, // Should this window be persistent?
- shouldDispose, // (see comment above)
- fSelf, // Part reference to us
- gGlobals->fFrameView, // What view should the window have?
- gGlobals->fMainPresentation, // What presentation should the window have?
- windowProperties->sourceFrame); // The display frame being opened, if any
- }
- else
- {
- // Tell OpenDoc about it by creating an OpenDoc window object.
- window = windowState->
- RegisterWindowForFrame(ev,
- platformWindow, // Macintosh WindowPtr
- frame, // Frame type (Persistent/Non-persistent)
- windowProperties->isRootWindow, // Is this a document window?
- windowProperties->isResizable, // Is this window resizeable?
- windowProperties->isFloating, // Is this window floating?
- saveWindow, // Should this window be persistent?
- shouldDispose, // (see comment above)
- windowProperties->sourceFrame); // The display frame being opened, if any
- }
-
- CATCH_ALL
- // Cleanup Macintosh Window.
- CloseWindow(platformWindow);
- ODDisposePtr(platformWindow);
- // Get the right error message for the problem.
- ODSShort errMsgNum = (!frame && windowProperties->sourceFrame)
- ? kErrCantOpenPartWindow : kErrCantOpenDocWindow;
- // Alert the user of the problem.
- this->DoDialogBox(ev, frame, kErrorBoxID, errMsgNum);
- // Change the exception value, so the DocShell doesn't display an
- // error dialog.
- SetErrorCode(kODErrAlreadyNotified);
- // Alert the caller.
- RERAISE;
- ENDTRY
- }
-
- return window;
- }
-
- //------------------------------------------------------------------------------
- // Method: CleanupWindow
- // Origin: PanelEditor
- //
- // Description: This method is called by the part when a window needs to be
- // cleaned up for a frame being closed/removed.
- //
- // The part deallocates the window buffer allocated in the
- // CreateWindow() method.
- //------------------------------------------------------------------------------
-
- void PanelEditor::CleanupWindow( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","CleanupWindow");
-
- TRY
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- if ( frameInfo->ShouldDisposeWindow() )
- {
- TempODWindow window = frame->AcquireWindow(ev);
- THROW_IF_NULL(window);
-
- ODPlatformWindow windowPtr = window->GetPlatformWindow(ev);
- CloseWindow(windowPtr);
- ODDisposePtr(windowPtr);
- }
- CATCH_ALL
- this->DoDialogBox(ev, frame, kErrorBoxID, kErrWindowGone);
- // consume excpetion because it's not fatal.
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: GetDefaultWindowProperties
- // Origin: PanelEditor
- //
- // Description: This method is called by the part when a new window is being
- // created. The method examines the frame which is being opened
- // a generates the default window parameters to pass to the
- // Mac Toolbox.
- //------------------------------------------------------------------------------
-
- WindowProperties*
- PanelEditor::GetDefaultWindowProperties( Environment* ev,
- ODFrame* sourceFrame,
- Rect* windowRect )
- {
- SOM_Trace("PanelEditor","GetDefaultWindowProperties");
-
- WindowProperties* windowProperties = new WindowProperties;
-
- TRY
- // Calculate the offset for the window based on the sourceFrame.
- if ( sourceFrame )
- this->CalcPartWindowPosition(ev, sourceFrame, windowRect);
- else
- OffsetRect(windowRect, kALittleNudge,
- GetMBarHeight() + kMacWindowTitleBarHeight);
-
- // Set the window bounds based on the calculated rect.
- windowProperties->boundsRect = *windowRect;
-
- // Get the part's name to use for the new window.
- TempODIText windowName = GetPartName(ev, fSelf, kODCategorySpace);
- // Convert the ODIText into a Pascal string.
- GetITextString(windowName, windowProperties->title);
-
- // Fill in the other fields of the Window Properties struct.
-
- windowProperties->procID = zoomDocProc;
- windowProperties->hasCloseBox = kODTrue;
- windowProperties->refCon = (long) kODNULL;
- windowProperties->wasVisible = kODFalse;
- windowProperties->isResizable = kODTrue;
- windowProperties->isFloating = kODFalse;
- windowProperties->isRootWindow = sourceFrame ? kODFalse : kODTrue;
- windowProperties->shouldShowLinks = kODFalse;
- windowProperties->sourceFrame = sourceFrame;
- CATCH_ALL
- // Clean up and...
- ODDeleteObject(windowProperties);
- // Alert the caller.
- RERAISE;
- ENDTRY
-
- return windowProperties;
- }
-
- //------------------------------------------------------------------------------
- // Method: GetSavedWindowProperties
- // Origin: PanelEditor
- //
- // Description: This method is called by the part to read in saved information
- // for a window from an existing document. In addition, the method
- // verifies that the window will open visible on some monitor.
- //------------------------------------------------------------------------------
-
- WindowProperties*
- PanelEditor::GetSavedWindowProperties( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","GetSavedWindowProperties");
-
- WindowProperties* windowProperties = new WindowProperties;
-
- // If we fail to load the window properties from storage, delete
- // the structure so the calling code will behave appropriately.
- if ( BeginGetWindowProperties(ev, frame, windowProperties) )
- {
- // Note: We don't call EndGetWindowProperties because it releases the
- // source frame, which we will need after this method returns.
-
- // Get the part's name to use for the new window.
- TempODIText windowName = GetPartName(ev, fSelf, kODCategorySpace);
- // Convert the ODIText into a Pascal string.
- GetITextString(windowName, windowProperties->title);
-
- // Verify the window is still visible on a monitor.
-
- RgnHandle windowRgn = ODNewRgn();
- ODBoolean repositionWindow = kODFalse;
-
- // We are only concerned with the window's title bar being
- // visible, so calcuate the titlebar rect from the current
- // window bounds.
- Rect adjustedBounds = windowProperties->boundsRect;
- adjustedBounds.bottom = adjustedBounds.top;
- adjustedBounds.top -= kMacWindowTitleBarHeight;
-
- // Intersect the monitor's region
- RectRgn(windowRgn, &adjustedBounds);
- SectRgn(windowRgn, GetGrayRgn(), windowRgn);
-
- if ( !EmptyRgn(windowRgn) )
- {
- // If the visible portion of the window is too small, we need
- // to reposition it.
- Rect intersectedBounds = (**windowRgn).rgnBBox;
- if ( (intersectedBounds.right-intersectedBounds.left < kMinHorzVisPortion) ||
- (intersectedBounds.bottom-intersectedBounds.top < kMinVertVisPortion) )
- repositionWindow = kODTrue;
- }
- else
- {
- // If the window is completely offscreen, we need to reposition it.
- repositionWindow = kODTrue;
- }
- ODDisposeHandle((ODHandle)windowRgn);
-
- // If not, we need to move it so the user can see it.
- if ( repositionWindow )
- {
- Rect windowRect = (windowProperties->boundsRect);
- // Move the window to {0,0} coordinates.
- OffsetRect(&windowRect, -windowRect.left, -windowRect.top);
- // Now move the window to the default window position.
- OffsetRect(&windowRect, kALittleNudge, GetMBarHeight() + kMacWindowTitleBarHeight);
- // Save the new window position in our windowProperties.
- windowProperties->boundsRect = windowRect;
- }
- }
- else
- {
- // If we were unable to re-load window properties, dispose of the
- // struct.
- ODDeleteObject(windowProperties);
- }
-
- return windowProperties;
- }
-
- //------------------------------------------------------------------------------
- // Method: CalcPartWindowSize
- // Origin: PanelEditor
- //
- // Description: This method is called by the part to determine what size a new
- // window shoud be.
- //------------------------------------------------------------------------------
-
- Rect PanelEditor::CalcPartWindowSize( Environment* ev,
- ODFrame* sourceFrame )
- {
- SOM_Trace("PanelEditor","CalcPartWindowSize");
-
- Rect windowRect;
-
- // If a source frame is given, the part is being asked to open one of
- // its display frames into a part window. Otherwise, we are being opened
- // as the root frame of the current document and should size the window
- // accordingly.
-
- // Set up the child window's size to be that of the display frame being opened.
- if ( sourceFrame )
- {
- GetQDFrameBounds(ev, sourceFrame, &windowRect);
- }
- // Otherwise, just open a large window.
- else
- {
- SetRect(&windowRect, 0, 0, kDefaultWinWidth, kDefaultWinHeight);
- }
-
- return windowRect;
- }
-
- //------------------------------------------------------------------------------
- // Method: CalcPartWindowPosition
- // Origin: PanelEditor
- //
- // Description: This method is called by the part to determine where to align
- // the new window (top left corner of the screen or tiled to a
- // frame).
- //------------------------------------------------------------------------------
-
- Rect PanelEditor::CalcPartWindowPosition( Environment* ev,
- ODFrame* frame,
- Rect* partWindowBounds )
- {
- SOM_Trace("PanelEditor","CalcPartWindowPosition");
-
- ODFacet* activeFacet;
- ODShape* frameShape;
- ODRect bbox;
- Rect bounds;
-
- // We need to know which facet of the frame we are opening to position
- // the child window.
- activeFacet = this->GetActiveFacetForFrame(ev, frame);
-
- // This should never occur, but if it did, it would be fatal.
- // So we will just pass back the same rectangle.
- if ( activeFacet == kODNULL )
- return *partWindowBounds;
-
- // For the purposes of tiling, we need the to know the area of the
- // document the frame occupies. We do this by getting the bouding
- // box and offsetting it by the aggregate external window transform
- // of the facet.
-
- frameShape = activeFacet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL);
- TempODTransform windowFrameTransform = activeFacet->AcquireWindowFrameTransform(ev, kODNULL);
- TempODShape boundsShape = ODCopyAndRelease(ev, frameShape);
-
- // Translate the bounds rect into window coordinates.
- boundsShape->Transform(ev, windowFrameTransform);
-
- // Get and convert the bounding box into a QuickDraw rectangle.
- boundsShape->GetBoundingBox(ev, &bbox);
- FixedToIntRect(bbox, bounds);
-
- // We then call our method to tile the child window.
- *partWindowBounds = TilePartWindow(ev, &bounds, partWindowBounds);
-
- // Set the port and origin so we can convert the rect to
- // global Window Mgr coordinates.
- SetPort(activeFacet->GetCanvas(ev)->GetQDPort(ev));
- SetOrigin(0,-kMacWindowTitleBarHeight);
-
- // Convert the local coordinates to global Window Mgr coordinates.
- LocalToGlobal((Point*)(&(partWindowBounds->top)));
- LocalToGlobal((Point*)(&(partWindowBounds->bottom)));
-
- return *partWindowBounds;
- }
-
- //------------------------------------------------------------------------------
- // Method: ZoomPartWindow
- // Origin: PanelEditor
- //
- // Description: This method is called by the part when a frame is being opened
- // or closed in the case that zooming rectangles should be shown.
- //------------------------------------------------------------------------------
-
- void PanelEditor::ZoomPartWindow( Environment* ev,
- ODFrame* frame,
- ODWindow* window,
- ODBoolean openingWindow )
- {
- SOM_Trace("PanelEditor","ZoomPartWindow");
-
- const ODSShort kNumZoomSteps = 12;
-
- Rect frameRect;
- {
- // We need to know which facet of the frame we are opening to position
- // the child window.
- ODFacet* zoomFacet = kODNULL;
-
- TRY
- zoomFacet = this->GetActiveFacetForFrame(ev, frame);
- CATCH_ALL
- ENDTRY
-
- // In case there isn't an active facet for the frame, .
- if ( zoomFacet == kODNULL )
- {
- TempODFrameFacetIterator iter(ev, frame);
- zoomFacet = iter.First();
- }
-
- if ( zoomFacet != kODNULL )
- {
- // For doing the zoom rects, we need the to know the area of the
- // document the frame occupies. We do this by getting the bouding
- // box and offsetting it by the aggregate external window transform
- // of the facet.
- TempODTransform windowFrameTransform =
- zoomFacet->AcquireWindowFrameTransform(ev, kODNULL);
- TempODShape boundsShape =
- ODCopyAndRelease(ev, zoomFacet->GetFrame(ev)
- ->AcquireFrameShape(ev, kODNULL));
-
- // Translate the bounds rect into window coordinates.
- boundsShape->Transform(ev, windowFrameTransform);
-
- // Get and convert the bounding box into a QuickDraw rectangle.
- ODRect bbox;
- boundsShape->GetBoundingBox(ev, &bbox);
- FixedToIntRect(bbox, frameRect);
-
- // Set the port and origin so we can convert the rect to
- // global Window Mgr coordinates.
- SetPort(zoomFacet->GetCanvas(ev)->GetQDPort(ev));
- SetOrigin(0, 0);
-
- // Convert the local coordinates to global Window Mgr coordinates.
- LocalToGlobal((Point*) &frameRect.top);
- LocalToGlobal((Point*) &frameRect.bottom);
- }
- }
-
- Rect windowRect;
- {
- ODPlatformWindow platformWindow = window->GetPlatformWindow(ev);
-
- windowRect = platformWindow->portRect;
- windowRect.top -= kMacWindowTitleBarHeight;
-
- // Set the port and origin so we can convert the rect to
- // global Window Mgr coordinates.
- SetPort(platformWindow);
- SetOrigin(0, 0);
-
- // Convert the local coordinates to global Window Mgr coordinates.
- LocalToGlobal((Point*) &windowRect.top);
- LocalToGlobal((Point*) &windowRect.bottom);
- }
-
- Rect fromRect = openingWindow ? frameRect : windowRect;
- Rect toRect = openingWindow ? windowRect : frameRect;
-
- if ( !openingWindow )
- window->Hide(ev);
-
- ZoomRects(&fromRect, &toRect, kNumZoomSteps,
- openingWindow ? zoomAccelerate : zoomDecelerate);
- }
-
- //------------------------------------------------------------------------------
- // Method: GetActiveFacetForFrame
- // Origin: Panel Editor
- //
- // Description: This method is called by the part when it needs to know what the
- // active facet is for the part, if any.
- //
- // The part uses this method specifically to find the facet of a
- // source frame when opening a part window.
- //------------------------------------------------------------------------------
-
- ODFacet* PanelEditor::GetActiveFacetForFrame( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","GetActiveFacetForFrame");
-
- ODFacet* facet = kODNULL;
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- // If the frame is active, and it should be, get the active facet
- // from the frame state info.
- if ( frameInfo->IsFrameActive() )
- {
- facet = frameInfo->GetActiveFacet();
- }
- else
- // Otherwise, iterate over the display frames looking for one
- // that has an active facet... there should be at least one.
- {
- TempODFrameFacetIterator fiter(ev, frame);
- for ( ODFacet* selectedFacet = fiter.First(); fiter.IsNotComplete();
- selectedFacet = fiter.Next() )
- {
- if ( selectedFacet->IsSelected(ev) )
- {
- facet = selectedFacet;
- break;
- }
- }
- }
-
- // If there are no active facets anywhere, this method should never
- // have been called, so signal an error.
- if ( facet == kODNULL )
- THROW(kODErrInvalidFrame);
-
- return facet;
- }
-
- //==============================================================================
- #pragma mark • Imaging •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: FacetAdded
- // Origin: ODPart
- //
- // Description: This method is called when any part adds a facet to
- // one of our display frames.
- //
- // The part calls ViewTypeChanged to load the appropriate
- // resource for display in this facet and then activates
- // the frame if we are the root part of an active window.
- //------------------------------------------------------------------------------
-
- void PanelEditor::FacetAdded( Environment* ev,
- ODFacet* facet )
- {
- SOM_Trace("PanelEditor","FacetAdded");
-
- ODFrame* frame = facet->GetFrame(ev);
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- // If this is the first facet being added to the frame, we prepare
- // for drawing in the appropriate view type.
-
- // If a frame had all of its facets removed, the frame would have
- // hidden any of its part windows. If the frame becomes visible again,
- // by having a facet added to it, we will "show" the part window for
- // the frame.
-
- if ( (CountFramesFacets(ev, frame) == 1) )
- {
- TempODWindow window = frameInfo->AcquirePartWindow(ev);
- if ( window ) window->Show(ev);
- }
-
- // If true, the frameshape we were given is too small. By now, our container
- // will have a "record" of this frame and we will be able to negotiate for
- // more space.
- if ( frameInfo->ShouldNegotiate() )
- {
- ODRect bounds;
-
- bounds.top = bounds.left = ff(0);
- bounds.right = ff(this->GetMinWidth());
- bounds.bottom = ff(this->GetMinHeight());
-
- TempODShape frameShape = facet->CreateShape(ev);
- frameShape->SetRectangle(ev, &bounds);
-
- TempODShape returnShape =
- facet->GetFrame(ev)->RequestFrameShape(ev, frameShape, kODNULL);
-
- frameInfo->SetShouldNegotiate(kODFalse);
- }
-
- // If this is the root frame/facet of a given window, we should activate
- // ourselves. This prevents OpenDoc from getting into an ambiguous
- // state.
-
- if ( frame->GetPresentation(ev) == gGlobals->fMainPresentation )
- {
- // Ask the list to add a facet to itself.
- fList->AddFacet(ev, facet);
- }
- else if ( frame->GetPresentation(ev) == gGlobals->fListPresentation )
- {
- // add facets to the embedded parts.
-
- COrdListIterator fiter(fEmbeddedParts);
- for ( CListItem* item = (CListItem*)fiter.First();
- fiter.IsNotComplete();
- item = (CListItem*)fiter.Next() )
- {
- item->AddFacet(ev, facet);
-
- if ( item == (CListItem*)fEmbeddedParts->First() )
- {
- // Select the first in the list.
- fSelection->Add(ev, item);
- // Change the panel frame display to the first item.
- fPanel->ChangeDisplayItem(ev, item);
- }
- }
-
- // If a root facet is being added, the frame should be activated when the
- // window is "selected". This prevents OpenDoc from getting into an
- // ambiguous state of no part having the selection focus.
-
- TempODFrame containingFrame = frame->AcquireContainingFrame(ev);
- if ( containingFrame->IsRoot(ev) )
- {
- frameInfo->SetFrameReactivate(kODTrue);
-
- // In addition, we set the "active" facet because the user can
- // perform edit operations on the part before having clicked
- // in it. The edit operations (eg. Paste) need to have a facet
- // for setting up the drawing environment.
- frameInfo->SetActiveFacet(facet);
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: FacetRemoved
- // Origin: ODPart
- //
- // Description: This method is called when any part removes a facet
- // from one of our display frames.
- //
- // The part just removes the "active" note from the
- // appropriate display frame if necessary since this
- // facet will not be available, nor active, again.
- //------------------------------------------------------------------------------
-
- void PanelEditor::FacetRemoved( Environment* ev,
- ODFacet* facet )
- {
- SOM_Trace("PanelEditor","FacetRemoved");
-
- ODFrame* frame = facet->GetFrame(ev);
- TempODFrame containingFrame = frame->AcquireContainingFrame(ev);
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- // If the facet was the active facet, it can no longer be.
- if ( ODObjectsAreEqual(ev, frameInfo->GetActiveFacet(), facet) )
- frameInfo->SetActiveFacet(kODNULL);
-
- // If a frame has all of its facets removed and its containing frame set
- // to NULL, the frame becomes "hidden". If the frame owns a part window,
- // the part window should also be hidden.
-
- if ( (CountFramesFacets(ev, frame) == 0) &&
- (containingFrame == kODNULL) )
- {
- TempODWindow window = frameInfo->AcquirePartWindow(ev);
- if ( window ) window->Hide(ev);
- }
-
- if ( frame->GetPresentation(ev) == gGlobals->fMainPresentation )
- {
- // Remove the facets from the frames we've created.
- fList->RemoveFacet(ev, facet);
- fPanel->RemoveFacet(ev, facet);
- }
- else if ( frame->GetPresentation(ev) == gGlobals->fListPresentation )
- {
- // Iterate over the embedded items to remove facets.
- COrdListIterator fiter(fEmbeddedParts);
- for ( CListItem* item = (CListItem*)fiter.First();
- fiter.IsNotComplete();
- item = (CListItem*)fiter.Next() )
- {
- // Ask each item to destroy the appropriate facets.
- item->RemoveFacet(ev, facet);
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: AdjustBorderShape
- //
- // Description: This method is called when
- //------------------------------------------------------------------------------
-
- ODShape* PanelEditor::AdjustBorderShape(Environment *ev,
- ODFacet* /*embeddedFacet*/,
- ODShape* shape)
- {
- ODShape* border = kODNULL;
-
- // If the shape is non-null, then we are adjusting the active border
- // for the panel frame.
- if ( shape )
- {
- ODRect bounds;
- shape->GetBoundingBox(ev, &bounds);
-
- bounds.Inset(ff(-1),ff(-1));
- border = shape->NewShape(ev);
- border->SetRectangle(ev, &bounds);
-
- bounds.Inset(ff(4),ff(4));
- TempODShape subtShape = shape->NewShape(ev);
- subtShape->SetRectangle(ev, &bounds);
-
- border->Subtract(ev, subtShape);
- }
-
- return border;
- }
-
- //------------------------------------------------------------------------------
- // Method: Draw
- //
- // Description: This method is called when
- //------------------------------------------------------------------------------
- /*
- void PanelEditor::Invalidate(Environment* ev,
- ODFrame* frame)
- {
- frame->Invalidate(ev, kODNULL, kODNULL);
- }
- */
- //------------------------------------------------------------------------------
- // Method: Draw
- // Origin: ODPart
- //
- // Description: This method is called when a facet of a part's display
- // frame intersects the invalidated portion of an OpenDoc
- // window. The invalidShape parameter passed in is the
- // portion of the facet which has been invalidated.
- //
- // The part sets up the drawing environment using a
- // C++ helper class (CFocusFrame) and then calls the
- // appropriate drawing method based on the frame's
- // viewType.
- //------------------------------------------------------------------------------
-
- void PanelEditor::Draw( Environment* ev,
- ODFacet* facet,
- ODShape* invalidShape )
- {
- SOM_Trace("PanelEditor","Draw");
-
- // Focus the port and origin for drawing in our facet.
- // Note that this instance of the CFocusDrawingEnv class
- // is being allocated on the stack. When the execution
- // leaves the scope of this method, the destructor (which
- // cleans up the drawing environment) is automatically
- // called.
- CFocusFrame initiateDrawing(ev, facet, invalidShape);
- // CFocusFrame initiateDrawing(ev, facet);
-
- ODTypeToken view = facet->GetFrame(ev)->GetViewType(ev);
-
- if ( view == gGlobals->fLargeIconView || view == gGlobals->fSmallIconView )
- this->DrawIconView(ev, facet);
- else if ( view == gGlobals->fThumbnailView )
- this->DrawThumbnailView(ev, facet);
- else
- this->DrawFrameView(ev, facet);
- }
-
- //------------------------------------------------------------------------------
- // Method: DrawFrameView
- // Origin: PanelEditor
- //
- // Description: This method is called by the part when the frame being
- // drawn is in "frame" view.
- //------------------------------------------------------------------------------
-
- void PanelEditor::DrawFrameView( Environment* ev,
- ODFacet* facet )
- {
- SOM_Trace("PanelEditor","DrawFrameView");
-
- // check presentation and do the right thing.
- ODFrame* frame = facet->GetFrame(ev);
-
- if ( frame->GetPresentation(ev) == gGlobals->fMainPresentation )
- {
- // Fill the background with a light gray color
-
- RGBColor backColor;
- RGBColor rgbLtGray;
-
- rgbLtGray.red = rgbLtGray.green = rgbLtGray.blue = kLtGrayColor;
-
- // Get the closet color to our "default" from the current color table.
- Index2Color(Color2Index(&rgbLtGray), &rgbLtGray);
-
- GetBackColor(&backColor);
- RGBBackColor(&rgbLtGray);
-
- GrafPtr thePort;
- GetPort(&thePort);
- EraseRect(&thePort->portRect);
-
- RGBBackColor(&backColor);
-
- PenNormal();
- Rect box;
- GetQDFrameBounds(ev, frame, &box);
-
- // Leave space for the grow box and status line area.
- ODUShort slHeight = (frame->IsRoot(ev)) ? 15 : 0;
-
- // Draw divider line between list & panel.
- MoveTo(kDividerLeftEdge, box.top);
- Line(0, box.bottom-slHeight);
-
- // If we are embedded...
- if ( !frame->IsRoot(ev) )
- {
- // Frame the whole part.
- FrameRect(&box);
- }
- else
- {
- // Draw divider line where bottom scroll bar would be.
- MoveTo(0, box.bottom-15);
- LineTo(thePort->portRect.right, box.bottom-15);
- }
-
- // Ask the panel to draw itself.
- fPanel->Draw(ev,facet);
- }
- else if ( frame->GetPresentation(ev) == gGlobals->fListPresentation )
- {
- // Ask the list to draw itself.
- fList->Draw(ev,facet);
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: DrawIconView
- // Origin: PanelEditor
- //
- // Description: This method is called by the part when the frame being
- // drawn is in "standard icon" view.
- //
- // The part uses the Icon Utilities toolbox manager to
- // aid in drawing icons in active windows. The Guidelines
- // require a different appearance for selected icons in
- // inactive windows, which we do manually.
- //------------------------------------------------------------------------------
-
- void PanelEditor::DrawIconView( Environment* ev,
- ODFacet* facet )
- {
- SOM_Trace("PanelEditor","DrawIconView");
-
- Rect iconRect;
- IconTransformType transformType = ttNone;
- CFrameInfo* frameInfo;
- ODFrame* frame;
- ODTypeToken viewType;
-
- frame = facet->GetFrame(ev);
- viewType = frame->GetViewType(ev);
- frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- // Check to see if the facet is selected
- if ( facet->GetHighlight(ev) == kODFullHighlight )
- transformType = ttSelected;
-
- // Check to see if the frame has been opened into a part window.
- TempODWindow window = frameInfo->AcquirePartWindow(ev);
- if ( window && window->IsShown(ev) )
- transformType |= ttOpen;
-
- // Draw the icon.
- if ( viewType == gGlobals->fLargeIconView )
- SetRect(&iconRect, 0, 0, kODLargeIconSize, kODLargeIconSize);
- else // ( viewType == gGlobals->fSmallIconView )
- SetRect(&iconRect, 0, 0, kODSmallIconSize, kODSmallIconSize);
-
- CUsingLibraryResources res;
- PlotIconID(&iconRect, atAbsoluteCenter, transformType, kBaseResourceID);
- }
-
- //------------------------------------------------------------------------------
- // Method: DrawThumbnailView
- // Origin: PanelEditor
- //
- // Description: This method is called by the part when the frame being
- // drawn is in "thumbnail" view.
- //
- // The part uses a picture for its thumbnail view because
- // it has no intrinsic content. A picture resource is
- // probably not sufficient for parts with real content.
- //------------------------------------------------------------------------------
-
- void PanelEditor::DrawThumbnailView( Environment* ev,
- ODFacet* facet )
- {
- SOM_Trace("PanelEditor","DrawThumbnailView");
-
- // Create or retrieve a cached thumbnail picture.
- PicHandle thumbnail = this->GenerateThumbnail(ev, facet->GetFrame(ev));
-
- Rect bounds = (**thumbnail).picFrame;
- DrawPicture(thumbnail, &bounds);
- }
-
- //------------------------------------------------------------------------------
- // Method: GenerateThumbnail
- // Origin: PanelEditor
- //
- // Description: This method is called by the part to generate a thumbnail view
- // from the current content.
- //
- // The part has no content, so we merely load a picture.
- //------------------------------------------------------------------------------
-
- PicHandle PanelEditor::GenerateThumbnail( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","GenerateThumbnail");
-
- if ( gGlobals->fThumbnail == kODNULL )
- {
- // In cases where a part has been instantiated from scratch and has no
- // content (yet), it is appropriate to display a PICT or some graphic
- // in place of a "real" thumbnail.
-
- LoadThumbnail(ev, &gGlobals->fThumbnail);
-
- // If we were unable to load the PICT resource for whatever reason
- // we will default back to a "frame" view and throw the Resource
- // Manager error as an exception.
- if ( gGlobals->fThumbnail == kODNULL )
- {
- frame->ChangeViewType(ev, gGlobals->fFrameView);
-
- // There is a bug in ResError, when resources are not found,
- // which may cause noErr to be returned. If that is the case,
- // we throw resNotFound.
- THROW_IF_ERROR((ODError)ResError());
- THROW(resNotFound);
- }
- }
-
- return (PicHandle)gGlobals->fThumbnail;
- }
-
- //------------------------------------------------------------------------------
- // Method: GeometryChanged
- // Origin: ODPart
- //
- // Description: This method is called when the ExternalTransform or
- // ClipShape of a facet on one this part's display frames
- // changes.
- //------------------------------------------------------------------------------
-
- void PanelEditor::GeometryChanged( Environment* ev,
- ODFacet* facet,
- ODBoolean clipShapeChanged,
- ODBoolean /*externalTransformChanged*/ )
- {
- SOM_Trace("PanelEditor","GeometryChanged");
-
- }
-
- //------------------------------------------------------------------------------
- // Method: HighlightChanged
- // Origin: ODPart
- //
- // Description: This method is called when a facet....
- //------------------------------------------------------------------------------
-
- void PanelEditor::HighlightChanged(Environment* ev, ODFacet* facet)
- {
- ODFrame* frame = facet->GetFrame(ev);
-
- // The frame view has no "special" drawing characteristics
- // when opened or selected, so we don't need to update our
- // content.
-
- if ( frame->GetViewType(ev) != gGlobals->fFrameView )
- frame->Invalidate(ev, kODNULL, kODNULL);
- }
-
- //==============================================================================
- #pragma mark • Activation •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: BeginRelinquishFocus
- // Origin: ODPart
- //
- // Description: This method is called when another part (or possibly
- // ourself) is requesting a focus for one of its display
- // frames. Returning true means we are willing to give
- // up the requested focus.
- //
- // The part willingly gives up any focus unless it is the
- // modal focus which we don't want to give up until we
- // are completely done displaying a modal dialog.
- //------------------------------------------------------------------------------
-
- ODBoolean PanelEditor::BeginRelinquishFocus( Environment* ev,
- ODTypeToken focus,
- ODFrame* /*ownerFrame*/,
- ODFrame* proposedFrame )
- {
- SOM_Trace("PanelEditor","BeginRelinquishFocus");
-
- ODBoolean willRelinquish = kODTrue;
-
- // Another part is trying to put up a Modal dialog while we
- // are currently displaying ours. Deny the request.
- if ( focus == gGlobals->fModalFocus )
- {
- TempODPart proposedPart = proposedFrame->AcquirePart(ev);
- if ( ODObjectsAreEqual(ev, proposedPart, fSelf) == kODFalse)
- willRelinquish = kODFalse;
- }
-
- return willRelinquish;
- }
-
- //------------------------------------------------------------------------------
- // Method: CommitRelinquishFocus
- // Origin: ODPart
- //
- // Description: This method is called when it is actually time to give
- // up a focus that had been requested by another part (or
- // possibly ourself).
- //
- // The part calls its FocusLost method to handle the
- // "reliquishing" of the particular focus.
- //------------------------------------------------------------------------------
-
- void PanelEditor::CommitRelinquishFocus( Environment* ev,
- ODTypeToken focus,
- ODFrame* ownerFrame,
- ODFrame* /*proposedFrame*/ )
- {
- SOM_Trace("PanelEditor","CommitRelinquishFocus");
-
- // We agreed to give up our FocusSet and now we are being asked to
- // do so.
- this->FocusLost(ev, focus, ownerFrame);
- }
-
- //------------------------------------------------------------------------------
- // Method: AbortRelinquishFocus
- // Origin: ODPart
- //
- // Description: This method is called when another part (or possibly
- // ourself) requested a focus for one of its display
- // frames, but we returned kODFalse from
- // BeginRelinqishFocus for one, or all, of the requested
- // focus. At this point, we are being told to resume
- // ownership of the focus.
- //
- // The part calls its FocusAcquired method to handle the
- // re-"acquisition" of the particular focus.
- //------------------------------------------------------------------------------
-
- void PanelEditor::AbortRelinquishFocus( Environment* ev,
- ODTypeToken /*focus*/,
- ODFrame* /*ownerFrame*/,
- ODFrame* /*proposedFrame*/ )
- {
- SOM_Trace("PanelEditor","AbortRelinquishFocus");
-
- // Some parts may have suspended some events in the BeginRelinquishFocus
- // method. If so, they would resume those events here.
- }
-
- //------------------------------------------------------------------------------
- // Method: FocusAcquired
- // Origin: ODPart
- //
- // Description: This method is called when the Arbitrator has
- // registered us as the "owner" of the particular focus.
- // This can occur if we are explicitly assigned a focus, or if a
- // focus is transfered to one of the part's display frames.
- //
- // The part will request the other foci it needs to be "active". If
- // the part is successful, we notify ourself to become active.
- //------------------------------------------------------------------------------
-
- void PanelEditor::FocusAcquired( Environment* ev,
- ODTypeToken focus,
- ODFrame* ownerFrame )
- {
- SOM_Trace("PanelEditor","FocusAcquired");
-
- ODArbitrator* arbitrator = fSelf->GetStorageUnit(ev)->GetSession(ev)
- ->GetArbitrator(ev);
-
- if ( focus == gGlobals->fMenuFocus )
- {
- if ( arbitrator->RequestFocus(ev, gGlobals->fSelectionFocus, ownerFrame) )
- {
- this->PartActivated(ev, ownerFrame);
- }
- }
- else if ( focus == gGlobals->fSelectionFocus )
- {
- if ( arbitrator->RequestFocus(ev, gGlobals->fMenuFocus, ownerFrame) )
- {
- this->PartActivated(ev, ownerFrame);
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: FocusLost
- // Origin: ODPart
- //
- // Description: This method is called when the Arbitrator has
- // unregistered us as the "owner" of the particular
- // focus.
- //
- // The part unmarks the active frame if the selection
- // focus is lost.
- //------------------------------------------------------------------------------
-
- void PanelEditor::FocusLost( Environment* ev,
- ODTypeToken focus,
- ODFrame* ownerFrame )
- {
- SOM_Trace("PanelEditor","FocusLost");
-
- if ( focus == gGlobals->fSelectionFocus )
- {
- CFrameInfo* frameInfo = (CFrameInfo*) ownerFrame->GetPartInfo(ev);
- frameInfo->SetFrameActive(kODFalse);
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: RelinquishAllFoci
- // Origin: PanelEditor
- //
- // Description: This method is called when a frame is going away. The method
- // relinquishes all foci the frame owns.
- //------------------------------------------------------------------------------
-
- void PanelEditor::RelinquishAllFoci( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","RelinquishAllFoci");
-
- ODArbitrator* arbitrator = ODGetSession(ev, fSelf)->GetArbitrator(ev);
-
- TRY
- TempODFrame focusFrame = arbitrator->AcquireFocusOwner(ev, gGlobals->fSelectionFocus);
- if ( ODObjectsAreEqual(ev, focusFrame, frame) )
- {
- arbitrator->RelinquishFocus(ev, gGlobals->fSelectionFocus, frame);
- this->FocusLost(ev, gGlobals->fSelectionFocus, frame);
- }
- CATCH_ALL
- ENDTRY
-
- TRY
- TempODFrame focusFrame = arbitrator->AcquireFocusOwner(ev, gGlobals->fMenuFocus);
- if ( ODObjectsAreEqual(ev, focusFrame, frame) )
- {
- arbitrator->RelinquishFocus(ev, gGlobals->fMenuFocus, frame);
- this->FocusLost(ev, gGlobals->fMenuFocus, frame);
- }
- CATCH_ALL
- ENDTRY
-
- TRY
- TempODFrame focusFrame = arbitrator->AcquireFocusOwner(ev, gGlobals->fKeyboardFocus);
- if ( ODObjectsAreEqual(ev, focusFrame, frame) )
- {
- arbitrator->RelinquishFocus(ev, gGlobals->fKeyboardFocus, frame);
- this->FocusLost(ev, gGlobals->fKeyboardFocus, frame);
- }
- CATCH_ALL
- ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: PartActivated
- // Origin: PanelEditor
- //
- // Description: This method is called
- //------------------------------------------------------------------------------
-
- void PanelEditor::PartActivated( Environment* ev, ODFrame* frame )
- {
- SOM_Trace("PanelEditor","PartActivated");
-
- // We are required to re-validate the menubar before displaying it because
- // any part can/could swap the base menubar at any time.
- if ( gGlobals->fMenuBar->IsValid(ev) == kODFalse )
- {
- ODReleaseObject(ev, gGlobals->fMenuBar);
- gGlobals->fMenuBar = ODGetSession(ev,fSelf)->GetWindowState(ev)->CopyBaseMenuBar(ev);
-
- // After copying the "new" base menu bar, don't forget to re-install
- // your part's menus.
- }
-
- // Display our menu bar.
- gGlobals->fMenuBar->Display(ev);
-
- // And set our "active" state.
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- frameInfo->SetFrameActive(kODTrue);
- }
-
- //------------------------------------------------------------------------------
- // Method: ActivatePart
- // Origin: PanelEditor
- //
- // Description: This method is called by the part when a kODEvtMouseUp
- // occurs in an inactive frame in an active window, and
- // when an OpenDoc document comes forward.
- //
- // The part activates the frame by requesting the
- // UIFocusSet (created in Initialize) and by calling
- // FocusAcquired if we were successful. The method
- // returns true if no problems were encountered as a
- // signal to the caller that the part is now "active".
- //------------------------------------------------------------------------------
-
- ODBoolean PanelEditor::ActivateFrame( Environment* ev, ODFrame* frame )
- {
- SOM_Trace("PanelEditor","ActivatePart");
-
- ODBoolean activated = kODFalse;
-
- // Request the set of foci necessary to become active.
- if ( ODGetSession(ev,fSelf)->GetArbitrator(ev)
- ->RequestFocusSet(ev, gGlobals->fUIFocusSet, frame) )
- {
- // Activate the part.
- this->PartActivated(ev, frame);
- // We were able to become active.
- activated = kODTrue;
- }
-
- // Let our caller know we succeded or failed.
- return activated;
- }
-
- //------------------------------------------------------------------------------
- // Method: WindowActivating
- // Origin: PanelEditor
- //
- // Description: This method is called by the part when a window we are displayed
- // in changes from active to inactive, or the reverse.
- //
- // The part records the active frame, if any of the
- // display frames were active, so that the frame can be
- // re-activated when the document is switched into the
- // foreground.
- //------------------------------------------------------------------------------
-
- void PanelEditor::WindowActivating( Environment* ev,
- ODFrame* frame,
- ODBoolean activating )
- {
- SOM_Trace("PanelEditor","WindowActivating");
-
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- // The window is being activated and we had the selection focus when
- // the window was deactivated, so request it again.
- if ( activating && frameInfo->FrameNeedsReactivating() )
- {
- this->ActivateFrame(ev, fList->GetFrame(ev, frame));
- frameInfo->SetFrameReactivate(kODFalse);
- }
- // The window is being deactivated and we have the active part.
- // So give up our foci and remind ourselves that we need to request
- // the focus when the window is reactivated.
- else if ( !activating && frameInfo->IsFrameActive() )
- {
- frameInfo->SetFrameReactivate(kODTrue);
- }
-
- // The selection highlighting needs to change.
- fSelection->Activate(ev, frame, activating);
- }
-
- //------------------------------------------------------------------------------
- // Method: ProcessActivating
- // Origin: PanelEditor
- //
- // Description: This method is called by the part when a process
- // switch event (kODEvtOS) occurs.
- //
- // The part updates the highlighting of the selected items.
- //------------------------------------------------------------------------------
-
- void PanelEditor::ProcessActivating(Environment* ev,
- ODFrame* frame,
- ODBoolean resume )
- {
- SOM_Trace("PanelEditor","ProcessActivating");
-
- // The selection highlighting needs to change.
- fSelection->Activate(ev, frame, resume);
- }
-
- //==============================================================================
- #pragma mark • Event Handling •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: HandleEvent
- // Origin: ODPart
- //
- // Description: The method is called when an event, which falls into
- // the category of an owned focus, occurs. The two
- // exceptions to this are "mouse movement" events and
- // embedded frame events, which can occur when a part
- // owns no foci.
- //
- // The part returns true if the event was handled.
- //------------------------------------------------------------------------------
-
-
- ODBoolean PanelEditor::HandleEvent( Environment* ev,
- ODEventData* event,
- ODFrame* frame,
- ODFacet* facet,
- ODEventInfo* eventInfo )
- {
- SOM_Trace("PanelEditor","HandleEvent");
-
- ODBoolean eventHandled = kODFalse;
-
- // Event handling is basically the same as standard Macintosh applications,
- // except that the events have been renamed for cross-platform compatability.
-
- switch ( event->what )
- {
- case kODEvtMouseDownEmbedded:
- case kODEvtMouseUpEmbedded:
- case kODEvtMouseDown:
- case kODEvtMouseUp:
- eventHandled = this->HandleMouseEvent(ev, event, facet, eventInfo);
- break;
-
- case kODEvtKeyDown:
- case kODEvtAutoKey:
- // handle type selection in list
- break;
-
- case kODEvtMenu:
- eventHandled = this->HandleMenuEvent(ev, event, frame);
- break;
-
- case kODEvtActivate:
- // We are being notified that a window we are displayed in has
- // just been de/activated (un/hilighted).
- this->WindowActivating(ev, frame, (event->modifiers & activeFlag));
- eventHandled = kODTrue;
- break;
-
- case kODEvtOS:
- this->ProcessActivating(ev, frame, (event->message & resumeFlag));
- // We are being notified that a window we are display in has
- // just been suspened/resumed.
- eventHandled = kODTrue;
- break;
-
- case kODEvtMouseEnter:
- case kODEvtMouseLeave:
- SetCursor(&ODQDGlobals.arrow);
- eventHandled = kODTrue;
- break;
-
- case kODEvtMouseWithin:
- eventHandled = kODTrue;
- break;
-
- // $$$$$ remove when done
- case kODEvtNull:
- case kODEvtMouseDownBorder:
- case kODEvtMouseUpBorder:
- case kODEvtWindow:
- case kODEvtKeyUp:
- case kODEvtDisk:
-
- default:
- break;
- }
-
- return eventHandled;
- }
-
- //------------------------------------------------------------------------------
- // Method: AdjustMenus
- //
- // Description: This method is called when a kODEvtMouseDown event
- // occurs in the menubar and the part owns the "menu"
- // focus.
- //
- // The part enables the appropriate items for its current
- // state and updates the menu items to reflect this
- // editor.
- //------------------------------------------------------------------------------
-
- void PanelEditor::AdjustMenus( Environment* ev,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","AdjustMenus");
-
- // The menubar object always calls the root part's AdjustMenus method before
- // calling the menu focus owner's. Because of this, we need to validate the
- // menubar in the case where we are the root part.
- if ( frame->IsRoot(ev) )
- {
- // We are required to re-validate the menubar before displaying it because
- // any part can/could swap the base menubar at any time.
- if ( gGlobals->fMenuBar->IsValid(ev) == kODFalse )
- {
- ODReleaseObject(ev, gGlobals->fMenuBar);
- gGlobals->fMenuBar = ODGetSession(ev,fSelf)->GetWindowState(ev)->CopyBaseMenuBar(ev);
-
- // After copying the "new" base menu bar, don't forget to re-install
- // your part's menus.
- }
-
- // We support printing.
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandPageSetup, kODTrue);
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandPrint, kODTrue);
- }
-
- // We only need to adjust the menu when the list frame owns the menu focus.
- if ( frame->GetPresentation(ev) == gGlobals->fListPresentation )
- {
- // Enable the "View As Window" command when we are not the root part.
- TempODFrame containingFrame = frame->AcquireContainingFrame(ev);
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandViewAsWin, !containingFrame->IsRoot(ev));
-
- TRY
- Str63 text;
-
- // Get the "about" string from our library's resources.
- // (note: ODGetIndString focuses the resource fork for us)
- ODGetIndString(text, kMenuStringResID, kAboutTextID);
- // Create an IText object to pass into the menubar.
- TempODIText menuItem(CreateIText(gGlobals->fEditorsScript, gGlobals->fEditorsLanguage,
- (StringPtr)&text));
- // Change the "About" menu item text for our part.
- gGlobals->fMenuBar->SetItemString(ev, kODCommandAbout, menuItem);
- CATCH_ALL
- // consume exception
- ENDTRY
-
- #ifndef PE_ViewerBuild
- TRY
- ODBoolean haveSelection = !fSelection->IsEmpty();
-
- // Enable these commands if there is a selection.
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandCut, haveSelection);
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandCopy, haveSelection);
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandClear, haveSelection);
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandGetPartInfo, haveSelection);
-
- ODBoolean haveData = this->CheckClipboard(ev, frame);
-
- // Enable these commands if there is data on the clipboard.
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandPaste, haveData);
- CATCH_ALL
- // consume exception
- ENDTRY
- #endif
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: HandleMenuEvent
- // Origin: PanelEditor
- //
- // Description: This method is called by the part when a menu event is
- // received.
- //
- // Using the menu bar object, we determine what the menu
- // command is, and call the appropriate method to handle
- // it.
- //------------------------------------------------------------------------------
-
- ODBoolean PanelEditor::HandleMenuEvent( Environment* ev,
- ODEventData* event,
- ODFrame* frame )
- {
- SOM_Trace("PanelEditor","HandleMenuEvent");
-
- ODULong menuResult = event->message;
- ODUShort menu = HiWord(menuResult);
- ODUShort item = LoWord(menuResult);
-
- switch ( gGlobals->fMenuBar->GetCommand(ev, menu, item) )
- {
- case kODCommandAbout:
- this->DoDialogBox(ev, frame, kAboutBoxID);
- break;
-
- case kODCommandPageSetup:
- // If the user modified page setup, the print
- // job needs to be saved. We don't call our
- // internal SetDirty() method because the change
- // doesn't affect content.
- if ( fPrinter && fPrinter->PageSetup(ev) )
- ODGetDraft(ev, fSelf)->SetChangedFromPrev(ev);
- break;
-
- case kODCommandPrint:
- if ( fPrinter )
- {
- TempODFrame containingFrame(kODNULL);
-
- if ( frame->IsRoot(ev) )
- {
- ODAcquireObject(ev, frame);
- containingFrame = frame;
- }
- else
- {
- containingFrame = frame->AcquireContainingFrame(ev);
- }
-
- ODFrame* panelFrame = fPanel->GetContainedFrame(ev, containingFrame);
- if ( panelFrame )
- fPrinter->PrintDocument(ev, panelFrame);
- }
- break;
-
- case kODCommandViewAsWin:
- this->Open(ev, frame);
- break;
-
- case kODCommandCut:
- this->DoCut(ev, frame);
- break;
-
- case kODCommandCopy:
- this->DoCopy(ev, frame);
- break;
-
- case kODCommandPaste:
- this->DoPaste(ev, frame);
- break;
-
- case kODCommandPasteAs:
- this->DoPasteAs(ev, frame);
- break;
-
- case kODCommandClear:
- this->DoClear(ev, frame);
- break;
-
- case kODCommandGetPartInfo:
- this->DoPartInfo(ev, frame);
- break;
-
-
- // Other commands a part might handle
- case kODCommandOpen:
- case kODCommandInsert:
- case kODCommandSelectAll:
- case kODCommandPreferences:
- case kODCommandUndo:
- case kODCommandRedo:
-
- default:
- return kODFalse;
- }
-
- return kODTrue;
- }
-
- //------------------------------------------------------------------------------
- // Method: HandleMouseEvent
- //
- // Description: This method is called by the part when a mouse event
- // is recieved.
- //
- // A typical part would determine the event type(up/down)
- // and respond appropriately, but we have no "real"
- // content model, so we activate the part as appropriate
- // and call a generic method to handle the event.
- //
- // Remember: When a frame is inactive, the first mouse up event
- // should activate it; inactive frames do not recieve
- // kODEvtMouseDown events.
- //------------------------------------------------------------------------------
-
- ODBoolean PanelEditor::HandleMouseEvent( Environment* ev,
- ODEventData* event,
- ODFacet* facet,
- ODEventInfo* eventInfo )
- {
- SOM_Trace("PanelEditor","HandleMouseEvent");
-
- ODFrame* frame = facet->GetFrame(ev);
-
- // If the facet parameter is invalid, the mouse up occurred outside the
- // bounds of a Modal window, otherwise it should be treated normally.
-
- if ( facet != kODNULL )
- {
- ODWindow* window = facet->GetWindow(ev);
-
- Point where;
-
- // Get the localized mouse coordinates from the Event Info.
- where.h = FixedToInt(eventInfo->where.x);
- where.v = FixedToInt(eventInfo->where.y);
-
- if ( event->what == kODEvtMouseUp || event->what == kODEvtMouseUpEmbedded )
- {
- TRY
- // Activate inactive windows on the first mouse up event.
- if ( !window->IsActive(ev) )
- window->Select(ev);
- // Activate the frame (if needed) on all subsequent mouse up events.
- else
- {
- // Get our state information from the PartInfo of the frame.
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
-
- // If this frame is not the active one, activate it by requesting
- // the appropriate foci.
-
- if ( !frameInfo->IsFrameActive() )
- {
- if ( this->ActivateFrame(ev, fList->GetFrame(ev, frame)) )
- // Keep track of which facet was the last active for positioning
- // child windows.
- frameInfo->SetActiveFacet(facet);
- else
- // We were unable to acquire the necessary focus and activate it.
- return kODFalse;
- }
- }
- CATCH_ALL
- // exception consumed
- ENDTRY
- }
- else if ( event->what == kODEvtMouseDown )
- {
- // The root frame should never handle mouse events.
- if ( frame->GetPresentation(ev) == gGlobals->fListPresentation )
- {
- CScrollbar* scrollbar = (CScrollbar*) facet->GetPartInfo(ev);
-
- // Hit test scrollbar. If the click is in the scrollbar,
- // scroll the list; otherwise check for a hit on an item name.
- if ( scrollbar->HitTest(where) > 0 )
- {
- scrollbar->Scroll(ev, frame, where);
- }
- else
- {
- CListItem* item = kODNULL;
-
- // Select the item so the user gets instant feedback.
- if ( fList->HitTest(ev, facet, kODNULL, where, &item) )
- {
- // Remove all items from the selection.
- fSelection->Empty(ev, kODTrue);
- // Add the item to the selection if it's not already.
- fSelection->Add(ev, item);
- // Change the panel frame display to the newly selected item.
- fPanel->ChangeDisplayItem(ev, item);
- }
- }
- }
- }
- else if ( event->what == kODEvtMouseDownEmbedded )
- {
- CListItem* item = kODNULL;
-
- // Select the item so the user gets instant feedback.
- if ( fList->HitTest(ev, facet, eventInfo->embeddedFacet, where, &item) )
- {
- // Remove all items from the selection.
- fSelection->Empty(ev, kODTrue);
- // Add the item to the selection if it's not already.
- fSelection->Add(ev, item);
- }
-
- // Check to see if the user is attempting to drag the item.
- if ( fSelection->CheckForDrag(ev, event) )
- {
- // Drag the selected item.
- fSelection->Drag(ev, facet, event, eventInfo);
-
- // Verify list item positions and adjust the scrollbar setting.
- fList->AdjustItemPositions(ev);
- fList->AdjustScrollbar(ev);
-
- // Force redrawing.
- frame->Invalidate(ev, kODNULL, kODNULL);
- }
- else // If the event is just a click, update the panel display.
- {
- if ( item )
- // Change the panel frame display to the newly selected item.
- fPanel->ChangeDisplayItem(ev, item);
- }
- }
- }
- else
- {
- // User clicked outside the bounds of a Modal window, though we actually
- // never display one.
-
- SysBeep(1);
- }
-
- return kODTrue;
- }
-
- //------------------------------------------------------------------------------
- // Method: CheckClipboard
- // Origin: PanelEditor
- //
- // Description: This method is called by the part to check the clipboard for
- // valid data (stuff that can be pasted).
- //------------------------------------------------------------------------------
-
- ODBoolean PanelEditor::CheckClipboard(Environment* ev, ODFrame* frame)
- {
- SOM_Trace("PanelEditor","CheckClipboard");
-
- ODBoolean hasValidData = kODFalse;
-
- ODSession* session = ODGetSession(ev,fSelf);
- ODArbitrator* arbitrator = session->GetArbitrator(ev);
- ODClipboard* clipboard = session->GetClipboard(ev);
-
- if ( arbitrator->RequestFocus(ev, gGlobals->fClipboardFocus, frame) )
- {
- ODStorageUnit* su = clipboard->GetContentStorageUnit(ev);
-
- if ( su->Exists(ev, kODPropContents, kODNULL, 0) )
- hasValidData = kODTrue;
-
- arbitrator->RelinquishFocus(ev, gGlobals->fClipboardFocus, frame);
- }
-
- return hasValidData;
- }
-
- //------------------------------------------------------------------------------
- // Method: GetItemNearSelection
- // Origin: PanelEditor
- //
- // Description: This method is called to update the selected item. This will
- // typically be called after the user "removes" a list item.
- //------------------------------------------------------------------------------
-
- CListItem* PanelEditor::GetItemNearSelection()
- {
- // Grab the selection bounds so we can updated it after cutting
- // the selected items.
- CListItem* first = fSelection->GetFirstItem();
- CListItem* last = fSelection->GetLastItem();
-
- CListItem* item = kODNULL;
-
- if ( fEmbeddedParts->Count() > 1 )
- {
- item = (CListItem*) fEmbeddedParts->Before(first);
- if ( item == kODNULL )
- item = (CListItem*) fEmbeddedParts->After(last);
- }
-
- return item;
- }
-
- //------------------------------------------------------------------------------
- // Method: UpdateSelection
- // Origin: PanelEditor
- //
- // Description: This method is called to update the selected item. This will
- // typically be called after the user "removes" a list item.
- //------------------------------------------------------------------------------
-
- void PanelEditor::UpdateSelection(Environment* ev, CListItem* item)
- {
- if ( item )
- {
- // Select the item.
- fSelection->Add(ev, item);
- // Update the panel display.
- fPanel->ChangeDisplayItem(ev, item);
- }
- else
- {
- // The List is empty, clear the panel display.
- fPanel->RemoveAll(ev);
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: DoDialogBox
- // Origin: PanelEditor
- //
- // Description: This method is calle by the part when the user selects
- // the "About PanelEditor…" menu items.
- //------------------------------------------------------------------------------
-
- void PanelEditor::DoDialogBox( Environment* ev,
- ODFrame* frame,
- ODSShort dialogID,
- ODUShort errorNumber )
- {
- SOM_Trace("PanelEditor","DoDialogBox");
-
- ODFrame* focusFrame = frame;
- ODSession* session = ODGetSession(ev,fSelf);
-
- // If the calling method does not have a frame available to it, we need to
- // locate a frame to use for requesting the modal focus. Find the first valid
- // frame in our display frames list.
- if ( focusFrame == kODNULL )
- {
- CListIterator fiter(fDisplayFrames);
- for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
- fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
- {
- if ( proxy->FrameIsLoaded(ev) )
- focusFrame = proxy->GetFrame(ev);
- if ( focusFrame ) break;
- }
- }
-
- // Our About box is modal so we must request the Modal focus to prevent
- // multiple modal dialogs being displayed simultaneously.
-
- if ( session->GetArbitrator(ev)->RequestFocus(ev, gGlobals->fModalFocus, focusFrame) )
- {
- DialogPtr dialog;
- ODSShort itemHit;
-
- // Dim the frontmost document window.
- session->GetWindowState(ev)->DeactivateFrontWindows(ev);
-
- ODSLong rfRef;
- rfRef = BeginUsingLibraryResources();
- {
- dialog = GetNewDialog(dialogID, kODNULL, (WindowPtr) -1L);
-
- if ( dialog )
- {
- if ( errorNumber > 0 )
- {
- Handle itemHandle;
- Rect itemRect;
- short itemType;
- Str255 errStr;
-
- GetIndString(errStr, kErrorStringResID, errorNumber);
- GetDialogItem(dialog, kErrStrFieldID, &itemType, &itemHandle, &itemRect);
- SetDialogItemText(itemHandle, errStr);
-
- // We don't need the cancel button for an error dialog.
- HideDialogItem(dialog, cancel);
-
- SetDialogDefaultItem(dialog, ok);
- }
-
- SetCursor(&ODQDGlobals.arrow);
- ShowWindow(dialog);
- ModalDialog(kODNULL, &itemHit);
- DisposeDialog(dialog);
- }
- else
- {
- // Could not load About box dialog... something is amiss.
- SysBeep(2);
- }
- }
- EndUsingLibraryResources(rfRef);
-
- // Inform the Arbitrator that we no longer require the Modal focus.
- session->GetArbitrator(ev)->RelinquishFocus(ev, gGlobals->fModalFocus, focusFrame);
-
- // Hilite the frontmost document window.
- session->GetWindowState(ev)->ActivateFrontWindows(ev);
- }
- else
- // If we can't get the modal focus, then another modal dialog is
- // already being displayed.
- SysBeep(2);
- }
-
-
- #ifndef PE_ViewerBuild
-
- //------------------------------------------------------------------------------
- // Method: DragEnter
- // Origin: ODPart
- //
- // Description: This method is called on the part when the user is dragging data
- // over the "active" areas of the part (ie. the list frame).
- //
- // The part displays dragging feedback, but does not check the drag
- // contents
- //------------------------------------------------------------------------------
-
- ODDragResult PanelEditor::DragEnter(Environment *ev, ODDragItemIterator* /*dragInfo*/,
- ODFacet* facet, ODPoint* /*where*/)
- {
- DragReference dragRef;
- Rect listRect;
- RgnHandle dragHilite = ODNewRgn();
-
- TRY
- SetCursor(&ODQDGlobals.arrow);
-
- dragRef = ODGetSession(ev,fSelf)->GetDragAndDrop(ev)->GetDragReference(ev);
-
- // Focus the port for drawing.
- CFocusFrame initiateDrawing(ev, facet);
-
- // Get the bounding box of the frame in quickdraw coordinates.
- GetQDFrameBounds(ev, facet->GetFrame(ev), &listRect);
-
- // Move the right side of the rectangle inside the scrollbar;
- listRect.right -= 15;
-
- InsetRect(&listRect, 1, 1);
- RectRgn(dragHilite, &listRect);
-
- // Show the Mac Drag Mgr highlighting in our frame.
- ShowDragHilite(dragRef, dragHilite, true);
-
- CATCH_ALL
- ENDTRY
-
- ODDisposeHandle((ODHandle)dragHilite);
-
- return kODTrue;
- }
-
- //------------------------------------------------------------------------------
- // Method: DoDialogBox
- // Origin: ODPart
- //
- // Description: This method is calle by the part when the user selects
- //------------------------------------------------------------------------------
-
- ODDragResult PanelEditor::DragWithin(Environment *ev, ODDragItemIterator* /*dragInfo*/,
- ODFacet* /*facet*/, ODPoint* /*where*/)
- {
- return kODTrue;
- }
-
-
- //------------------------------------------------------------------------------
- // Method: DoDialogBox
- //
- // Description: This method is calle by the part when the user selects
- //------------------------------------------------------------------------------
-
- void PanelEditor::DragLeave(Environment *ev, ODFacet* facet, ODPoint* /*where*/)
- {
- DragReference dragRef =
- ODGetSession(ev,fSelf)->GetDragAndDrop(ev)->GetDragReference(ev);
-
- // Focus the port for drawing.
- CFocusFrame initiateDrawing(ev, facet);
-
- // Hide the Mac Drag Mgr highlighting.
- HideDragHilite(dragRef);
- }
-
- //------------------------------------------------------------------------------
- // Method: Drop
- //
- // Description: This method is calle by the part when the user selects
- //------------------------------------------------------------------------------
-
- ODDropResult PanelEditor::Drop(Environment *ev, ODDragItemIterator* dropInfo,
- ODFacet* facet, ODPoint* where)
- {
- DragReference dragRef;
- ODDropResult result = kODDropFail;
- ODCloneKind method;
- ODFrame* frame = facet->GetFrame(ev);
- ODSession* session = ODGetSession(ev,fSelf);
-
- // Determine the nature of the drag (copy vs. move).
- {
- ODBoolean option;
- ODBoolean control;
- ODSShort mouseDownModifiers;
- ODSShort mouseUpModifiers;
- ODULong dragAttributes;
-
- dragAttributes = session->GetDragAndDrop(ev)->GetDragAttributes(ev);
- dragRef = session->GetDragAndDrop(ev)->GetDragReference(ev);
-
- GetDragModifiers(dragRef, 0L, &mouseDownModifiers, &mouseUpModifiers);
- option = (mouseDownModifiers & optionKey) || (mouseUpModifiers & optionKey);
- control = (mouseDownModifiers & controlKey) || (mouseUpModifiers & controlKey);
-
- if ( control ) result = kODDropMove;
- else if ( option ) result = kODDropCopy;
- else result = kODDropMove;
-
- // The user dropped the item in the source frame.
- if ( !control && kODDropMove && (dragAttributes & kODDragIsInSourceFrame) )
- result = kODDropFail;
- }
-
- // Focus the port for drawing.
- CFocusFrame initiateDrawing(ev, facet);
-
- // hide drag hilite
- HideDragHilite(dragRef);
-
- // If the drop is valid, process it.
- if ( result != kODDropFail )
- {
- // Determine what to tell the draft if we need to clone parts and/or
- // frames from the Drag&Drop su.
- method = (result == kODDropMove ? kODCloneDropMove : kODCloneDropCopy);
-
- // Clear the current selection.
- fSelection->Empty(ev);
-
- // Read in the data from each of the Drag & Drop StorageUnits.
- for (ODStorageUnit* dragSU = dropInfo->First(ev); dragSU; dragSU = dropInfo->Next(ev))
- {
- ODDraft* fromDraft = dragSU->GetDraft(ev);
- ODDraft* toDraft = fSelf->GetStorageUnit(ev)->GetDraft(ev);
- ODDraftKey draftKey;
- ODID partID;
-
- ODVolatile(fromDraft);
- ODVolatile(draftKey);
-
- // Since we only allow embedding of other parts, it makes sense to check
- // for a "content" property in each storage unit before trying to embed
- // it. Otherwise, we might end up with the "gray box" part.
-
- if ( dragSU->Exists(ev, kODPropContents, kODNULL, 0) )
- {
- draftKey = fromDraft->BeginClone(ev, toDraft, kODNULL, method);
-
- TRY
- partID = fromDraft->Clone(ev, draftKey, dragSU->GetID(ev), 0, 0);
- fromDraft->EndClone(ev, draftKey);
-
- // Create a proxy for the new item
- this->EmbedNewItem(ev, facet, partID);
-
- // Allow the user to undo/redo the drag operation.
- fSelection->PushUndoState(ev, kUndoDrop, kODSingleAction);
- CATCH_ALL
- fromDraft->AbortClone(ev, draftKey);
- RERAISE;
- ENDTRY
- }
- }
-
- // Verify list item positions and adjust the scrollbar setting.
- fList->AdjustItemPositions(ev);
- fList->AdjustScrollbar(ev);
-
- //$$$$$ this shoud be optimized to invalidate just the new item area.
- frame->Invalidate(ev, kODNULL, kODNULL);
-
- // Dirty the draft.
- this->SetDirty(ev);
- }
-
- return result;
- }
-
- #endif // #ifndef PE_ViewerBuild
-
- //------------------------------------------------------------------------------
- // Method: DoPartInfo
- //
- // Description: This method is calle by the part when the user selects
- //------------------------------------------------------------------------------
-
- void PanelEditor::DoPartInfo(Environment* ev, ODFrame* frame)
- {
- SOM_Trace("PanelEditor","DoPartInfo");
-
- // Focus for drawing. If the user changes the name we want to
- // update it instantaneously.
- CFocusFrame initiateDrawing(ev, this->GetActiveFacetForFrame(ev, frame));
-
- // Display (serially) the part info dialog for the items
- // in the selection.
- fSelection->ShowPartInfo(ev, frame);
- }
-
- //------------------------------------------------------------------------------
- // Method: DoCut
- //
- // Description: This method is calle by the part when the user selects
- //------------------------------------------------------------------------------
-
- void PanelEditor::DoCut(Environment* ev, ODFrame* frame)
- {
- SOM_Trace("PanelEditor","DoCut");
-
- // Get a valid item to add to the selection.
- CListItem* item = this->GetItemNearSelection();
-
- // Clear the items in the selection.
- fSelection->Cut(ev, frame);
-
- // Verify list item positions.
- fList->AdjustItemPositions(ev);
- // Adjust the scrollbar setting.
- fList->AdjustScrollbar(ev);
- // Update the selection.
- this->UpdateSelection(ev, item);
-
- // Force redrawing.
- frame->Invalidate(ev, kODNULL, kODNULL);
-
- // Dirty the draft.
- this->SetDirty(ev);
- }
-
- //------------------------------------------------------------------------------
- // Method: DoCopy
- //
- // Description: This method is calle by the part when the user selects
- //------------------------------------------------------------------------------
-
- void PanelEditor::DoCopy(Environment* ev, ODFrame* frame)
- {
- SOM_Trace("PanelEditor","DoCopy");
-
- // Copy the items in the selection.
- fSelection->Copy(ev, frame);
- }
-
- //------------------------------------------------------------------------------
- // Method: DoPaste
- //
- // Description: This method is calle by the part when the user selects
- //------------------------------------------------------------------------------
-
- void PanelEditor::DoPaste(Environment* ev, ODFrame* frame)
- {
- SOM_Trace("PanelEditor","DoPaste");
-
- ODFacet* facet = this->GetActiveFacetForFrame(ev, frame);
-
- // Acquire the clipboard focus and write the selection to it.
-
- ODSession* session = ODGetSession(ev,fSelf);
- ODArbitrator* arbitrator = session->GetArbitrator(ev);
- ODClipboard* clipboard = session->GetClipboard(ev);
-
- if ( arbitrator->RequestFocus(ev, gGlobals->fClipboardFocus, frame) )
- {
- ODStorageUnit* su = clipboard->GetContentStorageUnit(ev);
-
- ODDraft* fromDraft = su->GetDraft(ev);
- ODDraft* toDraft = ODGetDraft(ev,fSelf);
- ODDraftKey draftKey;
- ODID partID;
-
- ODVolatile(fromDraft);
- ODVolatile(draftKey);
-
- // Focus the port for drawing.
- CFocusFrame initiateDrawing(ev, facet);
-
- // Clear the current selection.
- fSelection->Empty(ev);
-
- draftKey = fromDraft->BeginClone(ev, toDraft, kODNULL, kODClonePaste);
-
- TRY
- partID = fromDraft->Clone(ev, draftKey, su->GetID(ev), 0, 0);
- fromDraft->EndClone(ev, draftKey);
-
- // Create a proxy for the new item.
- this->EmbedNewItem(ev, facet, partID);
-
- // Allow the user to undo/redo the clipboard operation.
- fSelection->PushUndoState(ev, kUndoPaste, kODSingleAction);
-
- // Adjust the clipshape for the new item.
- fList->ClipItems(ev);
- CATCH_ALL
- fromDraft->AbortClone(ev, draftKey);
- ENDTRY
-
- arbitrator->RelinquishFocus(ev, gGlobals->fClipboardFocus, frame);
- }
-
- // Adjust the scrollbar settings.
- fList->AdjustScrollbar(ev);
-
- // Dirty the draft.
- this->SetDirty(ev);
- }
-
- //------------------------------------------------------------------------------
- // Method: DoPasteAs
- //
- // Description: This method is calle by the part when the user selects
- //------------------------------------------------------------------------------
-
- void PanelEditor::DoPasteAs(Environment* ev, ODFrame* frame)
- {
- SOM_Trace("PanelEditor","DoPasteAs");
-
- // $$$$$ dialog
-
- //
- this->DoPaste(ev, frame);
-
- // Verify list item positions and adjust the scrollbar setting.
- fList->AdjustItemPositions(ev);
- fList->AdjustScrollbar(ev);
-
- // Dirty the draft.
- this->SetDirty(ev);
- }
-
- //------------------------------------------------------------------------------
- // Method: DoClear
- //
- // Description: This method is calle by the part when the user selects
- //------------------------------------------------------------------------------
-
- void PanelEditor::DoClear(Environment* ev, ODFrame* frame)
- {
- SOM_Trace("PanelEditor","DoClear");
-
- // Get a valid item to add to the selection.
- CListItem* item = this->GetItemNearSelection();
-
- // Clear the items in the selection.
- fSelection->Clear(ev, frame);
-
- // Verify list item positions.
- fList->AdjustItemPositions(ev);
- // Adjust the scrollbar setting.
- fList->AdjustScrollbar(ev);
- // Update the selection.
- this->UpdateSelection(ev, item);
-
- // Force redrawing.
- frame->Invalidate(ev, kODNULL, kODNULL);
-
- // Dirty the draft.
- this->SetDirty(ev);
- }
-
- //------------------------------------------------------------------------------
- // Method: UndoAction
- //
- // Description: This method is calle by the part when the user selects
- //------------------------------------------------------------------------------
-
- void PanelEditor::UndoAction(Environment* ev, ODActionData* action)
- {
- SOM_Trace("PanelEditor","UndoAction");
-
- fSelection->Undo(ev, ((CUndo*)action->_buffer));
-
- // Adjust the scrollbar settings.
- //fList->AdjustScrollbar(ev);
- }
-
- //------------------------------------------------------------------------------
- // Method: RedoAction
- //
- // Description: This method is calle by the part when the user selects
- //------------------------------------------------------------------------------
-
- void PanelEditor::RedoAction(Environment* ev, ODActionData* action)
- {
- SOM_Trace("PanelEditor","RedoAction");
-
- fSelection->Redo(ev, ((CUndo*)action->_buffer));
-
- // Adjust the scrollbar settings.
- //fList->AdjustScrollbar(ev);
- }
-
- //------------------------------------------------------------------------------
- // Method: DisposeActionState
- //
- // Description: This method is calle by the part when the user selects
- //------------------------------------------------------------------------------
-
- void PanelEditor::DisposeActionState(Environment* ev, ODActionData* action,
- ODDoneState doneState)
- {
- SOM_Trace("PanelEditor","DisposeActionState");
-
- CUndo* undoObj = (*((CUndo**)action->_buffer));
- delete undoObj;
- }
-
-
-
-
-
-
-
-
-
-